Fixed #23733 -- Fixed squashing migrations that depend on multiple apps.
This commit is contained in:
parent
cc25bfebd5
commit
fd061b6591
|
@ -221,6 +221,13 @@ class MigrationLoader(object):
|
|||
for child_key in reverse_dependencies.get(replaced, set()):
|
||||
if child_key in migration.replaces:
|
||||
continue
|
||||
# child_key may appear in a replacement
|
||||
if child_key in reverse_replacements:
|
||||
for replaced_child_key in reverse_replacements[child_key]:
|
||||
if replaced in replacing[replaced_child_key].dependencies:
|
||||
replacing[replaced_child_key].dependencies.remove(replaced)
|
||||
replacing[replaced_child_key].dependencies.append(key)
|
||||
else:
|
||||
normal[child_key].dependencies.remove(replaced)
|
||||
normal[child_key].dependencies.append(key)
|
||||
normal[key] = migration
|
||||
|
|
|
@ -239,6 +239,27 @@ class LoaderTests(TestCase):
|
|||
|
||||
recorder.flush()
|
||||
|
||||
@override_settings(MIGRATION_MODULES={
|
||||
"app1": "migrations.test_migrations_squashed_complex_multi_apps.app1",
|
||||
"app2": "migrations.test_migrations_squashed_complex_multi_apps.app2",
|
||||
})
|
||||
@modify_settings(INSTALLED_APPS={'append': [
|
||||
"migrations.test_migrations_squashed_complex_multi_apps.app1",
|
||||
"migrations.test_migrations_squashed_complex_multi_apps.app2",
|
||||
]})
|
||||
def test_loading_squashed_complex_multi_apps(self):
|
||||
loader = MigrationLoader(connection)
|
||||
loader.build_graph()
|
||||
|
||||
plan = set(loader.graph.forwards_plan(('app1', '4_auto')))
|
||||
expected_plan = set([
|
||||
('app1', '4_auto'),
|
||||
('app1', '2_squashed_3'),
|
||||
('app2', '1_squashed_2'),
|
||||
('app1', '1_auto')
|
||||
])
|
||||
self.assertEqual(plan, expected_plan)
|
||||
|
||||
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed_erroneous"})
|
||||
def test_loading_squashed_erroneous(self):
|
||||
"Tests loading a complex but erroneous set of squashed migrations"
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(lambda apps, schema_editor: None)
|
||||
]
|
|
@ -0,0 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("app1", "1_auto")]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(lambda apps, schema_editor: None)
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
replaces = [
|
||||
("app1", "2_auto"),
|
||||
("app1", "3_auto"),
|
||||
]
|
||||
|
||||
dependencies = [("app1", "1_auto"), ("app2", "2_auto")]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(lambda apps, schema_editor: None)
|
||||
]
|
|
@ -0,0 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("app1", "2_auto"), ("app2", "2_auto")]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(lambda apps, schema_editor: None)
|
||||
]
|
|
@ -0,0 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("app1", "3_auto")]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(lambda apps, schema_editor: None)
|
||||
]
|
|
@ -0,0 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("app1", "1_auto")]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(lambda apps, schema_editor: None)
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
replaces = [
|
||||
("app2", "1_auto"),
|
||||
("app2", "2_auto"),
|
||||
]
|
||||
|
||||
dependencies = [("app1", "1_auto")]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(lambda apps, schema_editor: None)
|
||||
]
|
|
@ -0,0 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("app2", "1_auto")]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(lambda apps, schema_editor: None)
|
||||
]
|
Loading…
Reference in New Issue