Public repository: timo / mitch

Reader

A migration stitcher (therefore mitch) for PostgreSQL, SQLite, MariaDB, and others

docs(adr): record fingerprint, restore fallbacks and rebuild limits

public

docs(adr): record fingerprint, restore fallbacks and rebuild limits

Refs #2
Changesetde099355c4d00668b1c3002609f8690a36f7cbd5
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parents36a5d647d263
Children
Pushlog
by timo via ssh

modified docs/adr/cli/checkout/transition-plan-compares-ids-and-hashes.md +5 −1

@@ -3,6 +3,10 @@
33
 ---
44
 # The checkout transition plan compares migrations by ID and hash, not by path
55
 
6
-To decide what to revert before switching branches, checkout loads the migrations of the current and the target commit and compares them by ID and normalized hash. A migration is reverted when it is missing on the target or has a different hash there. Paths only locate the files.
6
+To decide what to revert before switching branches, checkout loads the migrations of the current and the target commit and compares them by ID and content. A migration is reverted when it is missing on the target or its content differs there. Paths only locate the files. The same comparison against the current commit finds the local edits that `stash` and `checkout --allow-dirty` reconcile first.
7
+
8
+Content means a fingerprint: the normalized up and down scripts, `dependencies`, `after`, `rebuild_dependants_of`, and the `transactional` and `idempotent` flags. Comparing the up script alone would let an edited down script or config through unnoticed, which the earlier path-based plan did catch.
9
+
10
+After checkout, mitch restores what it reverted. It finds each migration in the new state by ID; failing that, at the same path, because the config gave the file a new ID; failing that, as a migration with the same fingerprint under an ID the old state did not have, because the file was renamed. The last two fallbacks keep the earlier behaviour for changed IDs and renames. They can match a genuinely new migration that happens to reuse a path or the exact content, which is then applied without `--and-up`.
711
 
812
 The previous plan mapped `git diff --name-status` paths to migrations. That breaks after a rework: going back to a commit before the rework shows the archived `A@1.up.sql` as deleted and would revert A with all its dependants, although A is the same migration with the same hash on both commits, just under another path. Comparing identities also removes the special cases the path-based plan needed for changed IDs in configs, added or removed configs, and renamed files.

modified docs/adr/cli/rework/rework-keeps-the-previous-version-in-every-history.md +1 −1

@@ -15,7 +15,7 @@
1515
 
1616
 - The current files are archived next to the original as `A@1.up.sql`, `A@1.down.sql` and `A@1.config.toml`, with `id = "A"` in the config. The file at the original path gets `id = "A@2"`. The next rework archives `A@2.*` with `id = "A@2"` and gives the path `A@3`.
1717
 - The new down script is prefilled with A's up script, because reverting `A@2` must restore A's state while A stays applied.
18
-- The new config copies `transactional` and `idempotent` from A and gets a fresh `created_at`. It depends on A and lists all current transitive dependants of A as ordering constraints (`after`), so the new version runs after whatever of them a deployment has, without rolling out optional ones that it does not have.
18
+- The new config copies `transactional` and `idempotent` from A and gets a fresh `created_at`. It depends on the newest previous version and lists the current transitive dependants of every previous version in the own project as ordering constraints (`after`), so the new version runs after whatever of them a deployment has, without rolling out optional ones that it does not have. The commented-out `rebuild_dependants_of` names all previous versions for the same reason. Dependants in other projects cannot be listed, because a project only references projects it links.
1919
 - `mitch rework A` finds the newest version itself, and `status` and `log` group versions. Dependencies always name an exact version; there is no "A means the newest".
2020
 
2121
 ## Consequences

modified docs/adr/runner/rebuild-dependants-through-the-migration-graph.md +3 −0

@@ -19,5 +19,8 @@
1919
 
2020
 ## Consequences
2121
 
22
+- A rebuild re-applies the dependants after the migration, even when the migration declares ordering constraints on them, as a reworked version does. That is intended: an old and a fresh deployment both revert the dependants, apply the migration and re-apply them, so their histories stay the same.
23
+- Only `up` and `add` rebuild. When `checkout` or `stash` re-apply a migration that requests a rebuild, or when such a migration is reverted, no rebuild happens, and the same blocked `DROP` can occur.
24
+
2225
 - A rebuild is refused when a dependant has no down script or belongs to a project that is not loaded. Once destructive scripts can be marked, a destructive down script refuses it too, so a table with data is never dropped silently.
2326
 - An undeclared dependency surfaces as a failing `DROP` during rebuild. The fix is to declare it in mitch, which improves the graph.