Skip to content

Commit 774a6f8

Browse files
fix: add missing migration for token_blacklist app (#894)
* fix: add missing migration for token_blacklist app PR #879 modified both the OutstandingToken and BlacklistedToken models Meta class, but did not include the migration. This commit adds the missing migration file. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test: Add check for ungenerated migrations This adds a test to ensure all model changes are reflected in migrations. If ungenerated migrations are detected, the test will fail, enforcing migration consistency. References: - PR #894 - Issue #895 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent acb1483 commit 774a6f8

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 5.1.7 on 2025-03-23 06:56
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("token_blacklist", "0012_alter_outstandingtoken_user"),
9+
]
10+
11+
operations = [
12+
migrations.AlterModelOptions(
13+
name="blacklistedtoken",
14+
options={
15+
"verbose_name": "Blacklisted Token",
16+
"verbose_name_plural": "Blacklisted Tokens",
17+
},
18+
),
19+
migrations.AlterModelOptions(
20+
name="outstandingtoken",
21+
options={
22+
"ordering": ("user",),
23+
"verbose_name": "Outstanding Token",
24+
"verbose_name_plural": "Outstanding Tokens",
25+
},
26+
),
27+
]

tests/test_migrations.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from io import StringIO
2+
from typing import Optional
3+
4+
import pytest
5+
from django.core.management import call_command
6+
from django.test import TestCase
7+
8+
9+
class MigrationTestCase(TestCase):
10+
def test_no_missing_migrations(self):
11+
"""
12+
Ensures all model changes are reflected in migrations.
13+
If this test fails, there are model changes that require a new migration.
14+
15+
Behavior:
16+
- Passes silently if no migrations are required
17+
- Fails with a detailed message if migrations are need
18+
"""
19+
20+
output = StringIO()
21+
22+
# Initialize exception variable to track migration check result
23+
exec: Optional[SystemExit] = None
24+
25+
try:
26+
# Check for pending migrations without actually creating them
27+
call_command(
28+
"makemigrations", "--check", "--dry-run", stdout=output, stderr=output
29+
)
30+
except SystemExit as e:
31+
# Capture the SystemExit if migrations are needed (the command will had ended with exit code 1)
32+
exec = e
33+
34+
# If an exception was raised, verify it indicates no migration changes are required
35+
if exec is not None:
36+
self.assertEqual(
37+
exec.code,
38+
0, # 0 means no migrations needed
39+
f"Model changes detected that require migrations!\n"
40+
f"Please run `python manage.py makemigrations` to create the necessary migrations.\n\n"
41+
f"Detected Changes:\n{output.getvalue()}",
42+
)

0 commit comments

Comments
 (0)