MCPcopy
hub / github.com/tortoise/tortoise-orm / _migration_plan

Method _migration_plan

tortoise/migrations/executor.py:268–303  ·  view source on GitHub ↗
(
        self,
        targets: Iterable[MigrationTarget] | None,
        applied: set[MigrationKey],
        graph: MigrationGraph,
    )

Source from the content-addressed store, hash-verified

266 return plan
267
268 def _migration_plan(
269 self,
270 targets: Iterable[MigrationTarget] | None,
271 applied: set[MigrationKey],
272 graph: MigrationGraph,
273 ) -> list[PlanStep]:
274 plan: list[PlanStep] = []
275 target_list = (
276 list(targets)
277 if targets is not None
278 else [
279 MigrationTarget(app_label=key.app_label, name=key.name)
280 for key in graph.leaf_nodes()
281 ]
282 )
283 for target in target_list:
284 if target.name == "__latest__":
285 for leaf in graph.leaf_nodes(target.app_label):
286 leaf_target = MigrationTarget(app_label=leaf.app_label, name=leaf.name)
287 plan.extend(self._forward_plan(leaf_target, applied, graph))
288 continue
289 if target.name == "__first__":
290 for root in graph.root_nodes(target.app_label):
291 root_target = MigrationTarget(app_label=root.app_label, name=root.name)
292 plan.extend(
293 self._backward_plan(root_target, applied, graph, include_target=True)
294 )
295 continue
296 key = MigrationKey(app_label=target.app_label, name=target.name)
297 if key not in graph.nodes:
298 raise ValueError(f"Unknown migration target {key}")
299 if key in applied:
300 plan.extend(self._backward_plan(target, applied, graph))
301 else:
302 plan.extend(self._forward_plan(target, applied, graph))
303 return self._dedupe_plan(plan)
304
305 def _forward_plan(
306 self,

Callers 2

migrateMethod · 0.95
planMethod · 0.95

Calls 7

_forward_planMethod · 0.95
_backward_planMethod · 0.95
_dedupe_planMethod · 0.95
MigrationKeyClass · 0.90
MigrationTargetClass · 0.85
leaf_nodesMethod · 0.80
root_nodesMethod · 0.80

Tested by

no test coverage detected