Skip to main content

MIGRATION_2

Constant MIGRATION_2 

pub const MIGRATION_2: &str = "-- Migration 2 \u{2014} the projection store\'s checkpoint.\n--\n-- The number is this directory\'s sequence, so that a DBA applying the files in\n-- lexical order gets a working database for both roles. It is NOT this store\'s\n-- own version: `projection_store::SCHEMA_VERSION` is 1, because this is the\n-- first migration of the projection role, which has its own lineage and its own\n-- constant exactly as `happenstance-sqlite` does. The two roles are separated by\n-- features and a consumer taking only `event-store` never applies this file.\n--\n-- Applied by `migration::apply_projection`, gated behind `projection-store`, and\n-- idempotent for the same reason migration 1 is: the fixture creates one schema\n-- per instance and connects onto it more than once, and a migration that fails\n-- on the second connect reports a broken environment as an adapter defect.\n--\n-- The suite\'s own probe read model is deliberately NOT here. It lives as a\n-- constant behind the `conformance` feature, because a test table shipped inside\n-- an application\'s database is a defect no test in this repository could catch --\n-- every test enables the feature. A `.sql` file in this directory is, by\n-- construction, something a DBA applies.\n\nCREATE TABLE IF NOT EXISTS projection_checkpoint (\n    -- The `ProjectionId`, verbatim. `text` rather than a bounded `varchar`: the\n    -- contract validates the identifier and this column is not the place to\n    -- restate a limit that would then disagree with it.\n    projection_id text   NOT NULL PRIMARY KEY,\n\n    -- A `SequencePosition`, which is a `NonZeroU64`, in a signed `bigint`. The\n    -- gap is real and it is read back through a fallible conversion --\n    -- `PostgresProjectionStoreError::CheckpointOutOfRange` -- rather than by a\n    -- cast that would turn a corrupt row into a plausible position. The column\n    -- carries the cheap half of the same guard so that a wrong value cannot be\n    -- written in the first place.\n    position      bigint NOT NULL CHECK (position > 0),\n\n    -- STORED, never inferred. `Checkpoint` is three states and `Authority` is\n    -- two, and the third state -- `NeverRun` -- is the ABSENCE of this row.\n    -- That is why `reset` deletes rather than writing a sentinel: a sentinel\n    -- position would make a reset indistinguishable from a commit at the first\n    -- position, which is the defect PS-16\'s own rule exists to reject.\n    --\n    -- Text rather than an enum type or an integer. A `CREATE TYPE` is a second\n    -- schema object to migrate and to `IF NOT EXISTS` around (which Postgres\n    -- does not offer for types), and the value is read by a human with a\n    -- debugger far more often than by this module. The CHECK is what keeps it\n    -- honest, and it is the constraint an integer column could not carry\n    -- legibly.\n    authority     text   NOT NULL CHECK (authority IN (\'live\', \'rebuilding\'))\n);\n";
Available on crate feature projection-store and (crate features event-store or projection-store) only.
Expand description

The projection store’s schema, as SQL.

Exposed for the same reason MIGRATION_1 is: a consumer running their own migration tooling needs the text, and the alternative is that they copy it out of the repository and it drifts. Applying it is apply_projection.

It is idempotent, and it does not include the conformance suite’s probe read model — that table is the suite’s, lives behind the conformance feature, and has no business in an application’s database.