1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[1.7.x] Fixed #22861: Internal migrations done first so __first__ works

Thanks to Chris Beaven.
This commit is contained in:
Andrew Godwin
2014-06-17 23:27:03 -07:00
parent 1122d2979a
commit 819d5f0c89
10 changed files with 145 additions and 6 deletions

View File

@@ -51,11 +51,11 @@ class GraphTests(TestCase):
# Test roots and leaves
self.assertEqual(
graph.root_nodes(),
set([('app_a', '0001'), ('app_b', '0001')]),
[('app_a', '0001'), ('app_b', '0001')],
)
self.assertEqual(
graph.leaf_nodes(),
set([('app_a', '0004'), ('app_b', '0002')]),
[('app_a', '0004'), ('app_b', '0002')],
)
def test_complex_graph(self):
@@ -105,11 +105,11 @@ class GraphTests(TestCase):
# Test roots and leaves
self.assertEqual(
graph.root_nodes(),
set([('app_a', '0001'), ('app_b', '0001'), ('app_c', '0001')]),
[('app_a', '0001'), ('app_b', '0001'), ('app_c', '0001')],
)
self.assertEqual(
graph.leaf_nodes(),
set([('app_a', '0004'), ('app_b', '0002'), ('app_c', '0002')]),
[('app_a', '0004'), ('app_b', '0002'), ('app_c', '0002')],
)
def test_circular_graph(self):

View File

@@ -142,6 +142,26 @@ class LoaderTests(TestCase):
],
)
@override_settings(MIGRATION_MODULES={
"migrations": "migrations.test_migrations_first",
"migrations2": "migrations2.test_migrations_2_first",
})
@modify_settings(INSTALLED_APPS={'append': 'migrations2'})
def test_first(self):
"""
Makes sure the '__first__' migrations build correctly.
"""
migration_loader = MigrationLoader(connection)
self.assertEqual(
migration_loader.graph.forwards_plan(("migrations", "second")),
[
("migrations", "thefirst"),
("migrations2", "0001_initial"),
("migrations2", "0002_second"),
("migrations", "second"),
],
)
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_name_match(self):
"Tests prefix name matching"

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("migrations", "thefirst"),
("migrations2", "0002_second"),
]
operations = [
migrations.DeleteModel("Tribble"),
migrations.RemoveField("Author", "silly_field"),
migrations.AddField("Author", "rating", models.IntegerField(default=0)),
migrations.CreateModel(
"Book",
[
("id", models.AutoField(primary_key=True)),
("author", models.ForeignKey("migrations.Author", null=True)),
],
)
]

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
"Author",
[
("id", models.AutoField(primary_key=True)),
("name", models.CharField(max_length=255)),
("slug", models.SlugField(null=True)),
("age", models.IntegerField(default=0)),
("silly_field", models.BooleanField(default=False)),
],
),
migrations.CreateModel(
"Tribble",
[
("id", models.AutoField(primary_key=True)),
("fluffy", models.BooleanField(default=True)),
],
)
]