MCPcopy
hub / github.com/django/django / show_list

Method show_list

django/core/management/commands/showmigrations.py:80–133  ·  view source on GitHub ↗

Show a list of all migrations on the system, or only those of some named apps.

(self, connection, app_names=None)

Source from the content-addressed store, hash-verified

78 sys.exit(2)
79
80 def show_list(self, connection, app_names=None):
81 """
82 Show a list of all migrations on the system, or only those of
83 some named apps.
84 """
85 # Load migrations from disk/DB
86 loader = MigrationLoader(connection, ignore_no_migrations=True)
87 recorder = MigrationRecorder(connection)
88 recorded_migrations = recorder.applied_migrations()
89 graph = loader.graph
90 # If we were passed a list of apps, validate it
91 if app_names:
92 self._validate_app_names(loader, app_names)
93 # Otherwise, show all apps in alphabetic order
94 else:
95 app_names = sorted(loader.migrated_apps)
96 # For each app, print its migrations in order from oldest (roots) to
97 # newest (leaves).
98 for app_name in app_names:
99 self.stdout.write(app_name, self.style.MIGRATE_LABEL)
100 shown = set()
101 for node in graph.leaf_nodes(app_name):
102 for plan_node in graph.forwards_plan(node):
103 if plan_node not in shown and plan_node[0] == app_name:
104 # Give it a nice title if it's a squashed one
105 title = plan_node[1]
106 if graph.nodes[plan_node].replaces:
107 title += " (%s squashed migrations)" % len(
108 graph.nodes[plan_node].replaces
109 )
110 applied_migration = loader.applied_migrations.get(plan_node)
111 # Mark it as applied/unapplied
112 if applied_migration:
113 if plan_node in recorded_migrations:
114 output = " [X] %s" % title
115 else:
116 title += " Run 'manage.py migrate' to finish recording."
117 output = " [-] %s" % title
118 if self.verbosity >= 2 and hasattr(
119 applied_migration, "applied"
120 ):
121 output += (
122 " (applied at %s)"
123 % applied_migration.applied.strftime(
124 "%Y-%m-%d %H:%M:%S"
125 )
126 )
127 self.stdout.write(output)
128 else:
129 self.stdout.write(" [ ] %s" % title)
130 shown.add(plan_node)
131 # If we didn't print anything, then a small message
132 if not shown:
133 self.stdout.write(" (no migrations)", self.style.ERROR)
134
135 def show_plan(self, connection, app_names=None):
136 """

Callers 1

handleMethod · 0.95

Calls 9

applied_migrationsMethod · 0.95
_validate_app_namesMethod · 0.95
MigrationLoaderClass · 0.90
MigrationRecorderClass · 0.90
leaf_nodesMethod · 0.80
forwards_planMethod · 0.80
writeMethod · 0.45
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected