Repository navigation
Refuse to activate a replay when the view schema tables changed - #564
Merged
Merged
Conversation
Preparing a replay copies the structure of the view schema tables to the replay schema. A change made to the view schema tables after that, such as a migration adding a column, only reaches the tables that activation moves to the archive schema, so it is silently lost and the code expecting it breaks. Preparing now records a SHA-256 digest of every object in the pg_dump of the view schema tables, without pg_dump's comments and \restrict lines. Preparing for activation and activating dump the tables again and refuse to continue when a digest differs, naming the changed objects. Activating compares after locking the tables against schema changes, and only then locks them exclusively, which pg_dump would wait on. The replay schema is not compared, so its tables can still be changed after preparing. A replay prepared before this change has no digests and is not checked; a warning is logged instead.
There was a problem hiding this comment.
🟡 Changes recommended
Critical digest-filtering flaws discard pre-header table settings and multiline SQL literal content, allowing schema changes to go undetected and activation to silently restore the old layout or defaults.
2 open issues
What changed in this PR
This PR adds view-schema change checks to projector replay activation, aiming to prevent migrations made after replay preparation from being silently lost when tables are swapped.
Changes:
- Store per-object schema digests and check them before optimization and activation.
- Allow replay-schema changes and warn when older replays lack digests.
- Add regression tests and document the required migration and replay behavior.
| File | Description |
|---|---|
spec/lib/sequent/migrations/projectors_replayer_spec.rb |
Tests schema-change checks, recovery, and older-replay compatibility. |
lib/sequent/migrations/projectors_replayer.rb |
Records and compares schema digests; adjusts activation locking. |
docs/docs/concepts/migrations.md |
Explains schema-change restrictions and recovery. |
db/structure.sql |
Adds the digest column and migration version. |
db/migrate/20261110120000_sequent_add_view_schema_ddl_digests_to_replay_states.rb |
Adds nullable JSONB storage for replay schema digests. |
CHANGELOG.md |
Announces the checks and required Sequent migration. |
Review effort: Balanced
Lines inside a multiline string literal were dropped with the dump's comments, and the tablespace and access method pg_dump sets before the first table were dropped with its session settings, so changing either left the digests equal. Only the restrict meta-commands differ between dumps of the same schema.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

A replay copies the view schema tables' structure when it is prepared, and activation swaps the replayed tables in. A migration that changes a view schema table in between only reaches the table that activation moves to the archive schema, so the change is silently lost and the code that expects it breaks. Preparing now records a digest of every object in the pg_dump of the view schema tables, and preparing for activation and activating refuse to continue when one changed, naming it. The replay schema itself is not compared, so its tables can still be altered after preparing, for example to partition them. A replay prepared before this change has no digests and is activated with a warning.
Open question: applying a view schema change to the replay schema by hand doesn't change the stored digests, so activation still refuses. Accepting that would need something like an
accept_view_schema_changes!that records the digests again; it isn't included.