mirror of
https://github.com/django/django.git
synced 2025-04-01 12:06:43 +00:00
Fixed #23953 -- Made makemigrations continue number sequence for squashed migrations.
This commit is contained in:
parent
6e4ac28af0
commit
15683cdb95
@ -1329,8 +1329,11 @@ class MigrationAutodetector:
|
|||||||
def parse_number(cls, name):
|
def parse_number(cls, name):
|
||||||
"""
|
"""
|
||||||
Given a migration name, try to extract a number from the beginning of
|
Given a migration name, try to extract a number from the beginning of
|
||||||
it. If no number is found, return None.
|
it. For a squashed migration such as '0001_squashed_0004…', return the
|
||||||
|
second number. If no number is found, return None.
|
||||||
"""
|
"""
|
||||||
|
if squashed_match := re.search(r'.*_squashed_(\d+)', name):
|
||||||
|
return int(squashed_match[1])
|
||||||
match = re.match(r'^\d+', name)
|
match = re.match(r'^\d+', name)
|
||||||
if match:
|
if match:
|
||||||
return int(match[0])
|
return int(match[0])
|
||||||
|
@ -2670,6 +2670,12 @@ class AutodetectorTests(TestCase):
|
|||||||
('0001_initial', 1),
|
('0001_initial', 1),
|
||||||
('0002_model3', 2),
|
('0002_model3', 2),
|
||||||
('0002_auto_20380101_1112', 2),
|
('0002_auto_20380101_1112', 2),
|
||||||
|
('0002_squashed_0003', 3),
|
||||||
|
('0002_model2_squashed_0003_other4', 3),
|
||||||
|
('0002_squashed_0003_squashed_0004', 4),
|
||||||
|
('0002_model2_squashed_0003_other4_squashed_0005_other6', 5),
|
||||||
|
('0002_custom_name_20380101_1112_squashed_0003_model', 3),
|
||||||
|
('2_squashed_4', 4),
|
||||||
]
|
]
|
||||||
for migration_name, expected_number in tests:
|
for migration_name, expected_number in tests:
|
||||||
with self.subTest(migration_name=migration_name):
|
with self.subTest(migration_name=migration_name):
|
||||||
|
@ -1956,6 +1956,21 @@ class MakeMigrationsTests(MigrationTestBase):
|
|||||||
out_value = out.getvalue()
|
out_value = out.getvalue()
|
||||||
self.assertIn('Add field created to book', out_value)
|
self.assertIn('Add field created to book', out_value)
|
||||||
|
|
||||||
|
@override_settings(
|
||||||
|
MIGRATION_MODULES={'migrations': 'migrations.test_migrations_squashed'},
|
||||||
|
)
|
||||||
|
def test_makemigrations_continues_number_sequence_after_squash(self):
|
||||||
|
with self.temporary_migration_module(module='migrations.test_migrations_squashed'):
|
||||||
|
with captured_stdout() as out:
|
||||||
|
call_command(
|
||||||
|
'makemigrations',
|
||||||
|
'migrations',
|
||||||
|
interactive=False,
|
||||||
|
empty=True,
|
||||||
|
)
|
||||||
|
out_value = out.getvalue()
|
||||||
|
self.assertIn('0003_auto', out_value)
|
||||||
|
|
||||||
|
|
||||||
class SquashMigrationsTests(MigrationTestBase):
|
class SquashMigrationsTests(MigrationTestBase):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user