First phase of loading migrations from disk

This commit is contained in:
Andrew Godwin 2013-05-10 16:00:55 +01:00
parent cb4b0de49e
commit 9ce8354672
9 changed files with 265 additions and 9 deletions

View file

@ -0,0 +1,5 @@
from django.db import migrations
class Migration(migrations.Migration):
pass

View file

@ -0,0 +1,6 @@
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("migrations", "0001_initial")]

View file

View file

@ -1,5 +1,7 @@
from django.test import TransactionTestCase
from django.db.migrations.graph import MigrationsGraph, CircularDependencyException
from django.db import connection
from django.db.migrations.graph import MigrationGraph, CircularDependencyError
from django.db.migrations.loader import MigrationLoader
class GraphTests(TransactionTestCase):
@ -16,7 +18,7 @@ class GraphTests(TransactionTestCase):
app_b: 0001 <-- 0002 <-/
"""
# Build graph
graph = MigrationsGraph()
graph = MigrationGraph()
graph.add_dependency(("app_a", "0004"), ("app_a", "0003"))
graph.add_dependency(("app_a", "0003"), ("app_a", "0002"))
graph.add_dependency(("app_a", "0002"), ("app_a", "0001"))
@ -54,7 +56,7 @@ class GraphTests(TransactionTestCase):
app_c: \ 0001 <-- 0002 <-
"""
# Build graph
graph = MigrationsGraph()
graph = MigrationGraph()
graph.add_dependency(("app_a", "0004"), ("app_a", "0003"))
graph.add_dependency(("app_a", "0003"), ("app_a", "0002"))
graph.add_dependency(("app_a", "0002"), ("app_a", "0001"))
@ -85,7 +87,7 @@ class GraphTests(TransactionTestCase):
Tests a circular dependency graph.
"""
# Build graph
graph = MigrationsGraph()
graph = MigrationGraph()
graph.add_dependency(("app_a", "0003"), ("app_a", "0002"))
graph.add_dependency(("app_a", "0002"), ("app_a", "0001"))
graph.add_dependency(("app_a", "0001"), ("app_b", "0002"))
@ -93,6 +95,23 @@ class GraphTests(TransactionTestCase):
graph.add_dependency(("app_b", "0001"), ("app_a", "0003"))
# Test whole graph
self.assertRaises(
CircularDependencyException,
CircularDependencyError,
graph.forwards_plan, ("app_a", "0003"),
)
class LoaderTests(TransactionTestCase):
"""
Tests the disk and database loader.
"""
def test_load(self):
"""
Makes sure the loader can load the migrations for the test apps.
"""
migration_loader = MigrationLoader(connection)
graph = migration_loader.build_graph()
self.assertEqual(
graph.forwards_plan(("migrations", "0002_second")),
[("migrations", "0001_initial"), ("migrations", "0002_second")],
)