Skip to content

Remove non-main migration line rows when migrating down past version 1 - #1378

Draft
bgentry wants to merge 1 commit into
masterfrom
bg/migrate-line-down-v1
Draft

bgentry wants to merge 1 commit into
masterfrom
bg/migrate-line-down-v1

Conversation

@bgentry

@bgentry bgentry commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

DRAFT: not ready for review. Opened for evaluation; this may change before it is marked ready.

When a migration line other than main is migrated down through its version 1, rivermigrate leaves that version's row in river_migration. Only the main line's version 1 drops the table, so the "nothing left to delete" shortcut is wrong for other lines. With MigrateTx the same shortcut leaves rows for every version removed in the run. Afterwards, a later up migration skips the line's version 1, and a later down migration runs its down SQL a second time.

This limits both version 1 shortcuts to the main line, so other lines delete their rows like any other version. New tests cover a full down-and-up round trip on an alternate line, with and without an outer transaction, and stepping down from version 1 one step at a time.

The migrator treats version 1 as special when migrating down: the main
line's version 1 drops `river_migration`, so there's no row left to
delete. That special case applies to every line, though, and a
non-main line's version 1 doesn't touch `river_migration`. Migrating
such a line down through version 1 leaves its version 1 row in place,
and with `MigrateTx` it leaves the rows for every version removed in
that run. A later up migration then sees version 1 as still applied
and skips it, and another down migration reruns version 1's down SQL.

Scope both version 1 special cases (the per-version delete and the
batch delete used within an outer transaction) to the main line, so
other lines delete their rows like any other version.

Extend the alternate line tests to check that migrating fully down
removes all of the line's rows and that migrating back up reapplies
version 1, add a test that stepping down from version 1 removes its
row and leaves nothing more to migrate, and cover the same round trip
through `MigrateTx`.
@bgentry
bgentry force-pushed the bg/migrate-line-down-v1 branch from 40d5c06 to e35702c Compare September 24, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant