0
0
mirror of https://github.com/django/django.git synced 2024-11-29 06:03:25 +01:00

Included reverse deps in showmigrations

This commit is contained in:
Jarek Glowacki 2016-05-08 10:58:15 +10:00 committed by Markus Holtermann
parent 509379a161
commit c8df17b612
2 changed files with 23 additions and 22 deletions

View File

@ -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))

View File

@ -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()
)