Skip to main content

Module migration

Module migration 

Expand description

The schema, rendered for one NeonConfig and split into statements.

§Why this module exists at all, when happenstance-postgres has no analogue

That adapter compiles its migration in with include_str! and hands the whole string to one execute. Neither half of that works here.

  • The text cannot be constant. Its identifiers are not known until a NeonConfig exists, because there is no search_path to place an unqualified name with: the /sql proxy discards options=-c search_path=… from the connection string, and there is no session a SET could live in. So the file carries @…@ placeholders and this module renders them from the config’s own already-quoted, already-qualified identifiers.
  • The whole file cannot be one statement. The endpoint’s query field takes exactly one; a multi-statement string is refused with Database request failed and no code, detail or position — measured, and it is the least diagnosable error this endpoint produces. So the file is split here and sent as one non-interactive batch, which is still one round trip and still one BEGIN/COMMIT.

§The splitter is deliberately small, and the file is written for it

It strips whole-line -- comments and then splits on ;. That is not a SQL parser and must not become one: it is correct exactly while no statement in migrations/ contains a dollar-quoted body or a semicolon inside a literal, and this module’s own tests assert both. The moment one does, the honest move is a statement-per-constant module rather than a smarter regex — a splitter that is nearly a parser is the shape that silently cuts a plpgsql body in half.

The fixture’s fault injections are plpgsql, and they are deliberately not in migrations/ for that reason: they are built as separate SqlStatements at the call site, where no splitting happens.

Constants§

MIGRATION_1
The event log, before its identifiers are filled in.
MIGRATION_2
The projection checkpoint, before its identifiers are filled in.
MIGRATION_3
The event log’s write-group columns and their index (#420), before their identifiers are filled in.

Functions§

remint_statement
The re-mint, against config’s meta table: the one statement that replaces this store’s identity with a freshly minted one, and reads the new value back as base64.
render
Renders template against config and splits it into statements.
request
The whole of a rendered migration, as one non-interactive transaction.