Skip to content

GH-6137 Message store migrations never drop what the running version does not declare - #6138

Open
cyclr-adrian wants to merge 1 commit into
JasperFx:mainfrom
cyclr-adrian:fix/message-store-add-only-migrations
Open

cyclr-adrian wants to merge 1 commit into
JasperFx:mainfrom
cyclr-adrian:fix/message-store-add-only-migrations

Conversation

@cyclr-adrian

Copy link
Copy Markdown
Contributor

Fixes #6137.

The message store was migrated under CreateOrUpdate, which drops the columns, indexes and foreign keys a table model doesn't declare (#873). So a node on an older Wolverine stripped what a newer version had added to the store, either through its startup migration or through resources setup / AddResourceSetupOnStartup(). Nodes still on the newer version then broke: the dead letter columns and their data went, and so did the GH-5498 node record index.

Change

  • New internal Wolverine.RDBMS.AddOnlyStoreSchema.AddOnly(). It sets ITable.AddOnlyMigrations (weasel#629) on every table among the store's objects. Weasel then keeps additions and changes, withholds the drops, and logs each one it withholds.
  • It's applied where the stores hand their objects to a migration:
    • MessageDatabase.Objects. MySQL, PostgreSQL, SQL Server and SQLite migrate from it, including tenant databases, and so do Marten and Polecat through the PostgreSQL and SQL Server stores.
    • Oracle's Objects and OracleMessageStore.Admin.MigrateAsync, which reads AllObjects() directly.
  • It's set in one place, rather than in each Schema/*Table constructor and on each inline node, assignment, control queue and node record table, so a table added later can't miss it.
  • The MessageStoreResource.Setup comment no longer says CreateOrUpdate never drops data. A MySQL MySQL: wolverine_node_records housekeeping deadlocks (row trim vs inserts, age sweep vs row trim) #5498 comment that said an outside index is dropped by the next migration is updated too.

This is the trade-off QueueTable and ScheduledMessageTable already accept: a release that really needs to remove a column or index from the store now has to do it explicitly.

Tests

MySqlTests/Bug_6137_message_store_migrations_are_add_only.cs checks four things:

  • every table in the store's Objects is add-only;
  • a migration keeps a column (with its data and its own index) and an index that a "newer version" added;
  • the same holds for MigrateAsync(AutoCreate.CreateOrUpdate), which is what Setup runs;
  • a missing index the model declares is still created.

Without the MessageDatabase.Objects change, the first three fail. Run locally on .NET 11:

  • MySqlTests: 568/568 (mysql:8.0).
  • SqliteTests: 619 passed, 2 skipped (they also cover SQLite's table rebuild path).

I didn't run the PostgreSQL, SQL Server or Oracle suites locally.

Backport

Please consider a 6.x backport. The flag only protects a rollback to a version that has it, so the sooner it's in a 6.x release, the more rollbacks it covers, including 7.0 → 6.x. The same change applies to the 6.0 branch: MessageDatabase.Objects, plus Oracle's two call sites, if they're the same there. I'm happy to open that PR as well.

Related: JasperFx/weasel#924 / JasperFx/weasel#925. Weasel.MySql drops a column before its index, which gives error 1091 and a half-applied migration. This PR stops Wolverine's store from emitting those drops at all.

🤖 Generated with Claude Code

…version does not declare

The store was migrated under CreateOrUpdate, which drops the columns, indexes
and foreign keys a table model does not declare. A node on an older version
(its startup migration, or resources setup) therefore stripped what a newer
version had added to the store, while nodes on the newer version still used it:
the dead letter columns and their data, the JasperFxGH-5498 node record index.

Every table the relational stores migrate is now AddOnlyMigrations (weasel#629),
as the database queue tables already are. Weasel keeps additions and changes,
withholds the drops and logs them. MessageStoreResource.Setup's comment no
longer claims CreateOrUpdate never drops anything.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 11:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the add-only message-store migration changes.

No open issues 🎉

What changed in this PR

Addresses GH-6137 by making relational message-store migrations add-only, protecting schema additions from newer versions during rollbacks and rolling deployments.

Changes:

  • Applies a shared add-only helper to RDBMS and Oracle migration paths.
  • Adds MySQL regression tests for preserving extra columns, data, and indexes while still creating declared indexes.
  • Corrects comments describing migration behavior.
File Description
src/​Wolverine/​Persistence/​Durability/​MessageStoreResource.cs Corrects setup migration comments.
src/​Persistence/​Wolverine.RDBMS/​MessageDatabase.Weasel.cs Applies add-only behavior to shared store objects.
src/​Persistence/​Wolverine.RDBMS/​AddOnlyStoreSchema.cs Adds the shared table-marking helper.
src/​Persistence/​Oracle/​Wolverine.Oracle/​OracleMessageStore.Weasel.cs Marks Oracle schema objects add-only.
src/​Persistence/​Oracle/​Wolverine.Oracle/​OracleMessageStore.Admin.cs Protects Oracle’s direct migration path.
src/​Persistence/​MySql/​Wolverine.MySql/​MySqlMessageStore.cs Updates the index migration comment.
src/​Persistence/​MySql/​MySqlTests/​Bug_6137_message_store_migrations_are_add_only.cs Adds schema preservation and migration regression tests.

Review effort: Balanced

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.

Message store tables should set AddOnlyMigrations: a node on an older version drops the columns and indexes a newer version added

2 participants