MCPcopy
hub / github.com/django/django / show_plan

Method show_plan

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

Show all known migrations (or only those of the specified app_names) in the order they will be applied.

(self, connection, app_names=None)

Source from the content-addressed store, hash-verified

133 self.stdout.write(" (no migrations)", self.style.ERROR)
134
135 def show_plan(self, connection, app_names=None):
136 """
137 Show all known migrations (or only those of the specified app_names)
138 in the order they will be applied.
139 """
140 # Load migrations from disk/DB
141 loader = MigrationLoader(connection)
142 graph = loader.graph
143 if app_names:
144 self._validate_app_names(loader, app_names)
145 targets = [key for key in graph.leaf_nodes() if key[0] in app_names]
146 else:
147 targets = graph.leaf_nodes()
148 plan = []
149 seen = set()
150
151 # Generate the plan
152 for target in targets:
153 for migration in graph.forwards_plan(target):
154 if migration not in seen:
155 node = graph.node_map[migration]
156 plan.append(node)
157 seen.add(migration)
158
159 # Output
160 def print_deps(node):
161 out = []
162 for parent in sorted(node.parents):
163 out.append("%s.%s" % parent.key)
164 if out:
165 return " ... (%s)" % ", ".join(out)
166 return ""
167
168 for node in plan:
169 deps = ""
170 if self.verbosity >= 2:
171 deps = print_deps(node)
172 if node.key in loader.applied_migrations:
173 self.stdout.write("[X] %s.%s%s" % (node.key[0], node.key[1], deps))
174 else:
175 self.stdout.write("[ ] %s.%s%s" % (node.key[0], node.key[1], deps))
176 if not plan:
177 self.stdout.write("(no migrations)", self.style.ERROR)

Callers 1

handleMethod · 0.95

Calls 7

_validate_app_namesMethod · 0.95
MigrationLoaderClass · 0.90
leaf_nodesMethod · 0.80
forwards_planMethod · 0.80
appendMethod · 0.45
addMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected