Included reverse deps in showmigrations
This commit is contained in:
parent
509379a161
commit
c8df17b612
|
@ -26,7 +26,11 @@ class Command(BaseCommand):
|
||||||
)
|
)
|
||||||
formats.add_argument(
|
formats.add_argument(
|
||||||
'--plan', '-p', action='store_const', dest='format', const='plan',
|
'--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')
|
parser.set_defaults(format='list')
|
||||||
|
@ -99,26 +103,24 @@ class Command(BaseCommand):
|
||||||
for target in targets:
|
for target in targets:
|
||||||
for migration in graph.forwards_plan(target):
|
for migration in graph.forwards_plan(target):
|
||||||
if migration not in seen:
|
if migration not in seen:
|
||||||
plan.append(graph.nodes[migration])
|
node = graph.node_map[migration]
|
||||||
|
plan.append(node)
|
||||||
seen.add(migration)
|
seen.add(migration)
|
||||||
|
|
||||||
# Output
|
# Output
|
||||||
def print_deps(migration):
|
def print_deps(node):
|
||||||
out = []
|
out = []
|
||||||
for dep in migration.dependencies:
|
for parent in sorted(node.parents):
|
||||||
if dep[1] == "__first__":
|
out.append("%s.%s" % parent.key)
|
||||||
roots = graph.root_nodes(dep[0])
|
|
||||||
dep = roots[0] if roots else (dep[0], "__first__")
|
|
||||||
out.append("%s.%s" % dep)
|
|
||||||
if out:
|
if out:
|
||||||
return " ... (%s)" % ", ".join(out)
|
return " ... (%s)" % ", ".join(out)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
for migration in plan:
|
for node in plan:
|
||||||
deps = ""
|
deps = ""
|
||||||
if self.verbosity >= 2:
|
if self.verbosity >= 2:
|
||||||
deps = print_deps(migration)
|
deps = print_deps(node)
|
||||||
if (migration.app_label, migration.name) in loader.applied_migrations:
|
if node.key in loader.applied_migrations:
|
||||||
self.stdout.write("[X] %s%s" % (migration, deps))
|
self.stdout.write("[X] %s.%s%s" % (node.key[0], node.key[1], deps))
|
||||||
else:
|
else:
|
||||||
self.stdout.write("[ ] %s%s" % (migration, deps))
|
self.stdout.write("[ ] %s.%s%s" % (node.key[0], node.key[1], deps))
|
||||||
|
|
|
@ -228,39 +228,38 @@ class MigrateTests(MigrationTestBase):
|
||||||
"""
|
"""
|
||||||
out = six.StringIO()
|
out = six.StringIO()
|
||||||
call_command("showmigrations", format='plan', stdout=out)
|
call_command("showmigrations", format='plan', stdout=out)
|
||||||
self.assertIn(
|
self.assertEqual(
|
||||||
"[ ] migrations.0001_initial\n"
|
"[ ] migrations.0001_initial\n"
|
||||||
"[ ] migrations.0003_third\n"
|
"[ ] migrations.0003_third\n"
|
||||||
"[ ] migrations.0002_second",
|
"[ ] migrations.0002_second\n",
|
||||||
out.getvalue().lower()
|
out.getvalue().lower()
|
||||||
)
|
)
|
||||||
|
|
||||||
out = six.StringIO()
|
out = six.StringIO()
|
||||||
call_command("showmigrations", format='plan', stdout=out, verbosity=2)
|
call_command("showmigrations", format='plan', stdout=out, verbosity=2)
|
||||||
self.assertIn(
|
self.assertEqual(
|
||||||
"[ ] migrations.0001_initial\n"
|
"[ ] migrations.0001_initial\n"
|
||||||
"[ ] migrations.0003_third ... (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()
|
out.getvalue().lower()
|
||||||
)
|
)
|
||||||
|
|
||||||
call_command("migrate", "migrations", "0003", verbosity=0)
|
call_command("migrate", "migrations", "0003", verbosity=0)
|
||||||
|
|
||||||
out = six.StringIO()
|
out = six.StringIO()
|
||||||
call_command("showmigrations", format='plan', stdout=out)
|
call_command("showmigrations", format='plan', stdout=out)
|
||||||
self.assertIn(
|
self.assertEqual(
|
||||||
"[x] migrations.0001_initial\n"
|
"[x] migrations.0001_initial\n"
|
||||||
"[x] migrations.0003_third\n"
|
"[x] migrations.0003_third\n"
|
||||||
"[ ] migrations.0002_second",
|
"[ ] migrations.0002_second\n",
|
||||||
out.getvalue().lower()
|
out.getvalue().lower()
|
||||||
)
|
)
|
||||||
|
|
||||||
out = six.StringIO()
|
out = six.StringIO()
|
||||||
call_command("showmigrations", format='plan', stdout=out, verbosity=2)
|
call_command("showmigrations", format='plan', stdout=out, verbosity=2)
|
||||||
self.assertIn(
|
self.assertEqual(
|
||||||
"[x] migrations.0001_initial\n"
|
"[x] migrations.0001_initial\n"
|
||||||
"[x] migrations.0003_third ... (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()
|
out.getvalue().lower()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue