mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
First phase of loading migrations from disk
This commit is contained in:
parent
cb4b0de49e
commit
9ce8354672
9 changed files with 265 additions and 9 deletions
5
tests/migrations/migrations/0001_initial.py
Normal file
5
tests/migrations/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
pass
|
6
tests/migrations/migrations/0002_second.py
Normal file
6
tests/migrations/migrations/0002_second.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("migrations", "0001_initial")]
|
0
tests/migrations/migrations/__init__.py
Normal file
0
tests/migrations/migrations/__init__.py
Normal 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")],
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue