Phase 9, part 3: schema migrations for both databases

Migrations from schema 30 on are one list (internal/db/migrations.go),
written in SQLite's SQL and translated for Postgres (db.PostgresSQL)
unless one gives its own. On Postgres the whole migration is one
transaction under an advisory lock, and each step is recorded in
schema_migrations. TestSchemasMatch compares the two schemas (tables,
columns, types, NOT NULL, nocase, indexes), with and without a new
migration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 07:17:56 -07:00
co-authored by Claude Opus 5.5
parent 1b2947de7c
commit d827d507c1
9 changed files with 508 additions and 32 deletions
+17
View File
@@ -1909,6 +1909,23 @@ than planned: rather than helpers in every query, the SQL stays as it is
- Left for part 3: migrations after schema 29 on both databases, and what
replaces SQLite's backup before a migration.
**Part 3 built 2026-11-25** on `phase9`.
- Schema changes from 30 on are one list for both databases
(`internal/db/migrations.go`), written in SQLite's SQL. Postgres gets
them translated automatically (`db.PostgresSQL`: types, identity keys,
`nocase`, timestamp defaults), unless a migration gives its own. SQLite's
29 migrations are closed.
- On Postgres, the whole migration (creating the schema, then each step)
is one transaction under an advisory lock: a failure leaves the database
as it was, and several copies of the app can start together. Each step
is recorded in `schema_migrations` (version, note, the app's version,
when), in place of SQLite's backup before a migration; the operator's
own Postgres backups cover the rest. The app logs a migration on both.
- `TestSchemasMatch` (on Postgres) compares the two schemas, with and
without a new migration: tables, columns in order, types, `NOT NULL`,
case-insensitivity and named indexes. Checked by feeding it drift on
purpose: a type, a missing index, a missing `nocase`.
Nothing changes for the local user; this makes the rest possible. A
commit after each part; the whole test suite runs against both SQLite and
Postgres from part 2 on.