Skip to main content

MIGRATION_3

Constant MIGRATION_3 

pub const MIGRATION_3: &str = "-- Migration 3 \u{2014} write groups (#420), on the event log\'s lineage.\n--\n-- Which rows one `append`, or one ingested group with its compensation, wrote\n-- together, so a runner and a store peer can read the log back in the writes\n-- that made it (SY-39). `write_group` holds the lowest position the write put\n-- in, the same value on every row of it; `group_guard` holds the guard an\n-- ingested group arrived under, in `happenstance-sync`\'s stored form, on that\n-- first row only.\n--\n-- Rendered and split by `migration.rs`, as migration 1 is: no dollar quote and\n-- no semicolon inside a literal, and every identifier a placeholder. Additive\n-- and idempotent, `IF NOT EXISTS` throughout. Both columns are nullable with no\n-- default, so adding them rewrites no row. A row written before this migration\n-- has `NULL` in both and reads as a group of its own, named by its position;\n-- there is no backfill.\n--\n-- Apply it before deploying a build that writes these columns: such a build\n-- names `write_group` in every `INSERT`, and fails against a table without it.\n--\n-- An ingest writes a provisional negative `write_group` and replaces it in the\n-- same transaction, so no committed row holds one; no CHECK can say so, because\n-- a CHECK is evaluated per statement and the provisional value lives across two.\n--\n-- The index serves the group read. Partial, because a row from before this\n-- migration is found by its position through the primary key. Built inside the\n-- migration\'s batch, so it blocks writes while it builds; on a large existing\n-- table, create it first with `CREATE INDEX CONCURRENTLY` under the same name,\n-- and `IF NOT EXISTS` below then leaves it alone.\n\nALTER TABLE @event@ ADD COLUMN IF NOT EXISTS write_group bigint;\n\nALTER TABLE @event@ ADD COLUMN IF NOT EXISTS group_guard bytea;\n\nCREATE INDEX IF NOT EXISTS @write_group_idx@\n    ON @event@ (write_group)\n    WHERE write_group IS NOT NULL;\n";
Expand description

The event log’s write-group columns and their index (#420), before their identifiers are filled in.

write_group, on every row, the lowest position the write that put the row in gave out, and group_guard, on that first row only, the guard an ingested group arrived under. A runner and a store peer read the log back in whole writes through them (SY-39). Both nullable with no default, so adding them rewrites no row, and a row from before this migration reads as a group of its own.

Apply it after MIGRATION_1, before deploying this build, with request: every INSERT this build sends names write_group, and fails against a table without it. Idempotent, as MIGRATION_1 is, so applying both to any schema, fresh or migrated by an older build, brings it to what this build expects. Numbered 3 because that is the directory’s sequence; MIGRATION_2 belongs to the projection store. Declared below request so the lines above keep the numbers the decision records cite.