Skip to content

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

Merged
brandur merged 1 commit into
masterfrom
bg/migrate-line-down-v1
Sep 29, 2026
Merged

brandur merged 1 commit into
masterfrom
bg/migrate-line-down-v1

Conversation

@bgentry

@bgentry bgentry commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

@bgentry
bgentry force-pushed the bg/migrate-line-down-v1 branch from 40d5c06 to e35702c Compare September 24, 2026 17:35

@brandur brandur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems right. Going to bring it in.

@brandur
brandur marked this pull request as ready for review September 29, 2026 21:22
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`.
@brandur
brandur force-pushed the bg/migrate-line-down-v1 branch from e35702c to f57955a Compare September 29, 2026 21:24
@brandur
brandur merged commit 7fea33a into master Sep 29, 2026
15 checks passed
@brandur
brandur deleted the bg/migrate-line-down-v1 branch September 29, 2026 21:28
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.

2 participants