mongrator.planner¶
mongrator.planner
¶
plan_up(files, applied, target=None)
¶
Compute which migrations need to be applied in the forward direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
list[MigrationFile]
|
All known migration files, in chronological order. |
required |
applied
|
set[MigrationId]
|
Set of migration IDs already recorded in the tracking collection. |
required |
target
|
MigrationId | None
|
If given, apply only up to and including this migration ID. Raises MigrationNotFoundError if target is not in files. |
None
|
Returns:
| Type | Description |
|---|---|
MigrationPlan
|
A MigrationPlan with to_apply (pending) and to_skip (already applied). |
Source code in src/mongrator/planner.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
plan_down(files, applied, steps=1)
¶
Compute which migrations to roll back.
Rolls back the most recently applied migrations, up to steps of them.
Migrations are identified by their position in the applied set intersected
with the ordered file list (file order is the canonical order).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
list[MigrationFile]
|
All known migration files, in chronological order. |
required |
applied
|
set[MigrationId]
|
Set of migration IDs already recorded in the tracking collection. |
required |
steps
|
int
|
Number of most-recent applied migrations to roll back. |
1
|
Returns:
| Type | Description |
|---|---|
MigrationPlan
|
A MigrationPlan where to_apply contains the migrations to roll back |
MigrationPlan
|
(in reverse order) and to_skip contains those left untouched. |
Source code in src/mongrator/planner.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |