summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarek Glowacki <jarekwg@gmail.com>2016-05-08 10:58:15 +1000
committerMarkus Holtermann <info@markusholtermann.eu>2016-05-08 13:53:36 +0200
commitc8df17b6128a5311d9375da2b4a4885337b60e42 (patch)
treefbbd3be0a0b5c5d7ed1b528ca7d66f57be27a588
parent509379a161d179f9e973fbaf6393e879531756f6 (diff)
downloaddjango-c8df17b6128a5311d9375da2b4a4885337b60e42.tar.gz
Included reverse deps in showmigrations
-rw-r--r--django/core/management/commands/showmigrations.py28
-rw-r--r--tests/migrations/test_commands.py17
2 files changed, 23 insertions, 22 deletions
diff --git a/django/core/management/commands/showmigrations.py b/django/core/management/commands/showmigrations.py
index 0d239b1eef..767aca139d 100644
--- a/django/core/management/commands/showmigrations.py
+++ b/django/core/management/commands/showmigrations.py
@@ -26,7 +26,11 @@ class Command(BaseCommand):
)
formats.add_argument(
'--plan', '-p', action='store_const', dest='format', const='plan',
- help='Shows all migrations in the order they will be applied.',
+ help=(
+ 'Shows all migrations in the order they will be applied. '
+ 'With a verbosity level of 2 or above all direct migration dependencies '
+ 'and reverse dependencies (run_before) will be included.'
+ )
)
parser.set_defaults(format='list')
@@ -99,26 +103,24 @@ class Command(BaseCommand):
for target in targets:
for migration in graph.forwards_plan(target):
if migration not in seen:
- plan.append(graph.nodes[migration])
+ node = graph.node_map[migration]
+ plan.append(node)
seen.add(migration)
# Output
- def print_deps(migration):
+ def print_deps(node):
out = []
- for dep in migration.dependencies:
- if dep[1] == "__first__":
- roots = graph.root_nodes(dep[0])
- dep = roots[0] if roots else (dep[0], "__first__")
- out.append("%s.%s" % dep)
+ for parent in sorted(node.parents):
+ out.append("%s.%s" % parent.key)
if out:
return " ... (%s)" % ", ".join(out)
return ""
- for migration in plan:
+ for node in plan:
deps = ""
if self.verbosity >= 2:
- deps = print_deps(migration)
- if (migration.app_label, migration.name) in loader.applied_migrations:
- self.stdout.write("[X] %s%s" % (migration, deps))
+ deps = print_deps(node)
+ if node.key in loader.applied_migrations:
+ self.stdout.write("[X] %s.%s%s" % (node.key[0], node.key[1], deps))
else:
- self.stdout.write("[ ] %s%s" % (migration, deps))
+ self.stdout.write("[ ] %s.%s%s" % (node.key[0], node.key[1], deps))
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 28e32c1602..a5f31f08cb 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -228,39 +228,38 @@ class MigrateTests(MigrationTestBase):
"""
out = six.StringIO()
call_command("showmigrations", format='plan', stdout=out)
- self.assertIn(
+ self.assertEqual(
"[ ] migrations.0001_initial\n"
"[ ] migrations.0003_third\n"
- "[ ] migrations.0002_second",
+ "[ ] migrations.0002_second\n",
out.getvalue().lower()
)
out = six.StringIO()
call_command("showmigrations", format='plan', stdout=out, verbosity=2)
- self.assertIn(
+ self.assertEqual(
"[ ] migrations.0001_initial\n"
"[ ] migrations.0003_third ... (migrations.0001_initial)\n"
- "[ ] migrations.0002_second ... (migrations.0001_initial)",
+ "[ ] migrations.0002_second ... (migrations.0001_initial, migrations.0003_third)\n",
out.getvalue().lower()
)
-
call_command("migrate", "migrations", "0003", verbosity=0)
out = six.StringIO()
call_command("showmigrations", format='plan', stdout=out)
- self.assertIn(
+ self.assertEqual(
"[x] migrations.0001_initial\n"
"[x] migrations.0003_third\n"
- "[ ] migrations.0002_second",
+ "[ ] migrations.0002_second\n",
out.getvalue().lower()
)
out = six.StringIO()
call_command("showmigrations", format='plan', stdout=out, verbosity=2)
- self.assertIn(
+ self.assertEqual(
"[x] migrations.0001_initial\n"
"[x] migrations.0003_third ... (migrations.0001_initial)\n"
- "[ ] migrations.0002_second ... (migrations.0001_initial)",
+ "[ ] migrations.0002_second ... (migrations.0001_initial, migrations.0003_third)\n",
out.getvalue().lower()
)