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
NeonConfigexists, because there is nosearch_pathto place an unqualified name with: the/sqlproxy discardsoptions=-c search_path=…from the connection string, and there is no session aSETcould 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
queryfield takes exactly one; a multi-statement string is refused withDatabase request failedand nocode,detailorposition— 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 oneBEGIN/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
templateagainstconfigand splits it into statements. - request
- The whole of a rendered migration, as one non-interactive transaction.