Permalink
Browse files

Fixed #23071 -- Use last migration's name in dependency to other app

Changed the autodetector to lookup the name of the other app's last
migration in the graph and use that as dependency instead of using
__latest__.
  • Loading branch information...
dekkers committed Jul 14, 2014
1 parent b4cf7e3 commit 3582698c138a7a311d12a57d0b35359815e8dbc9
@@ -254,13 +254,13 @@ def _detect_changes(self, convert_apps=None, graph=None):
# If we can't find the other app, we add a first/last dependency,
# but only if we've already been through once and checked everything
if chop_mode:
- # If the app already exists, we add __latest__, as we don't know which
- # migration contains the target field.
+ # If the app already exists, we add a dependency on the last migration,
+ # as we don't know which migration contains the target field.
# If it's not yet migrated or has no migrations, we use __first__
- if graph and not graph.root_nodes(dep[0]):
- operation_dependencies.add((dep[0], "__first__"))
+ if graph and graph.leaf_nodes(dep[0]):
+ operation_dependencies.add(graph.leaf_nodes(dep[0])[0])
else:
- operation_dependencies.add((dep[0], "__latest__"))
+ operation_dependencies.add((dep[0], "__first__"))
else:
deps_satisfied = False
if deps_satisfied:
@@ -136,7 +136,7 @@ def get_migration_by_prefix(self, app_label, name_prefix):
return self.disk_migrations[results[0]]
def check_key(self, key, current_app):
- if (key[1] != "__first__" and key[1] != "__latest__") or key in self.graph:
+ if key[1] != "__first__" or key in self.graph:
return key
# Special-case __first__, which means "the first migration" for
# migrated apps, and is ignored for unmigrated apps. It allows
@@ -1059,7 +1059,8 @@ def test_first_dependency(self):
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_last_dependency(self):
"""
- Tests that a dependency to an app with existing migrations uses __latest__.
+ Tests that a dependency to an app with existing migrations uses the
+ last migration of that app.
"""
# Load graph
loader = MigrationLoader(connection)
@@ -1074,4 +1075,4 @@ def test_last_dependency(self):
self.assertOperationTypes(changes, 'otherapp', 0, ["CreateModel"])
self.assertOperationAttributes(changes, 'otherapp', 0, 0, name="Book")
# Right dependencies?
- self.assertEqual(changes['otherapp'][0].dependencies, [("migrations", "__latest__")])
+ self.assertEqual(changes['otherapp'][0].dependencies, [("migrations", "0002_second")])
@@ -122,26 +122,6 @@ def test_run_before(self):
],
)
- @modify_settings(INSTALLED_APPS={'append': 'basic'})
- @override_settings(MIGRATION_MODULES={
- "migrations": "migrations.test_migrations_latest",
- "basic": "migrations.test_migrations_latest_basic",
- })
- def test_latest(self):
- """
- Makes sure that __latest__ works correctly.
- """
- # Load and test the plan
- migration_loader = MigrationLoader(connection)
- self.assertEqual(
- migration_loader.graph.forwards_plan(("migrations", "0001_initial")),
- [
- ("basic", "0001_initial"),
- ("basic", "0002_second"),
- ("migrations", "0001_initial"),
- ],
- )
-
@override_settings(MIGRATION_MODULES={
"migrations": "migrations.test_migrations_first",
"migrations2": "migrations2.test_migrations_2_first",
@@ -1,13 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ("basic", "__latest__"),
- ]
-
- operations = []
@@ -1,11 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
- dependencies = []
-
- operations = []
@@ -1,13 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ("basic", "0001_initial"),
- ]
-
- operations = []

0 comments on commit 3582698

Please sign in to comment.