Skip to content

Refuse to activate a replay when the view schema tables changed - #564

Merged
erikrozendaal merged 2 commits into
masterfrom
replay-view-schema-digest
Nov 11, 2026
Merged

erikrozendaal merged 2 commits into
masterfrom
replay-view-schema-digest

Conversation

@erikrozendaal

Copy link
Copy Markdown
Member

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.

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.
@erikrozendaal
erikrozendaal requested a balanced review from Copilot November 11, 2026 12:58
@erikrozendaal
erikrozendaal marked this pull request as ready for review November 11, 2026 13:01

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.

🟡 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.
@erikrozendaal
erikrozendaal merged commit 182d690 into master Nov 11, 2026
8 checks passed
@erikrozendaal
erikrozendaal deleted the replay-view-schema-digest branch November 11, 2026 13:46
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