summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-07-25 08:53:57 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-07-25 08:53:57 -0700
commited4812692e3a103444303b0a3dd1429bbdf9511c (patch)
tree6c8015ba6ba8022cc4f980ec2e38b6158f62b11b
parentf9b7a0383c6f0fbadb83306db667675d9f9dd2b4 (diff)
parent3582698c138a7a311d12a57d0b35359815e8dbc9 (diff)
Merge pull request #2938 from dekkers/ticket_23071
Fixed #23071 -- Use last migration's name in dependency to other app
-rw-r--r--django/db/migrations/autodetector.py10
-rw-r--r--django/db/migrations/loader.py2
-rw-r--r--tests/migrations/test_autodetector.py5
-rw-r--r--tests/migrations/test_loader.py20
-rw-r--r--tests/migrations/test_migrations_latest/0001_initial.py13
-rw-r--r--tests/migrations/test_migrations_latest/__init__.py0
-rw-r--r--tests/migrations/test_migrations_latest_basic/0001_initial.py11
-rw-r--r--tests/migrations/test_migrations_latest_basic/0002_second.py13
-rw-r--r--tests/migrations/test_migrations_latest_basic/__init__.py0
9 files changed, 9 insertions, 65 deletions
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
index 36f0f020b2..fff5daf08e 100644
--- a/django/db/migrations/autodetector.py
+++ b/django/db/migrations/autodetector.py
@@ -254,13 +254,13 @@ class MigrationAutodetector(object):
# 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:
diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py
index 5465f0ad18..5c240ca739 100644
--- a/django/db/migrations/loader.py
+++ b/django/db/migrations/loader.py
@@ -136,7 +136,7 @@ class MigrationLoader(object):
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
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 4f7a682d2f..baa0ae5d9d 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -1069,7 +1069,8 @@ class AutodetectorTests(TestCase):
@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)
@@ -1084,4 +1085,4 @@ class AutodetectorTests(TestCase):
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")])
diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py
index c0f9f1a6dd..68d05d296f 100644
--- a/tests/migrations/test_loader.py
+++ b/tests/migrations/test_loader.py
@@ -122,26 +122,6 @@ class LoaderTests(TestCase):
],
)
- @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",
diff --git a/tests/migrations/test_migrations_latest/0001_initial.py b/tests/migrations/test_migrations_latest/0001_initial.py
deleted file mode 100644
index e16bb2152d..0000000000
--- a/tests/migrations/test_migrations_latest/0001_initial.py
+++ /dev/null
@@ -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 = []
diff --git a/tests/migrations/test_migrations_latest/__init__.py b/tests/migrations/test_migrations_latest/__init__.py
deleted file mode 100644
index e69de29bb2..0000000000
--- a/tests/migrations/test_migrations_latest/__init__.py
+++ /dev/null
diff --git a/tests/migrations/test_migrations_latest_basic/0001_initial.py b/tests/migrations/test_migrations_latest_basic/0001_initial.py
deleted file mode 100644
index 4df0594154..0000000000
--- a/tests/migrations/test_migrations_latest_basic/0001_initial.py
+++ /dev/null
@@ -1,11 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
- dependencies = []
-
- operations = []
diff --git a/tests/migrations/test_migrations_latest_basic/0002_second.py b/tests/migrations/test_migrations_latest_basic/0002_second.py
deleted file mode 100644
index 49f5b1966c..0000000000
--- a/tests/migrations/test_migrations_latest_basic/0002_second.py
+++ /dev/null
@@ -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 = []
diff --git a/tests/migrations/test_migrations_latest_basic/__init__.py b/tests/migrations/test_migrations_latest_basic/__init__.py
deleted file mode 100644
index e69de29bb2..0000000000
--- a/tests/migrations/test_migrations_latest_basic/__init__.py
+++ /dev/null