chore(db): update schema version in the same transaction as migration (#10321)

Just to be entirely sure that if the migration succeeds the schema
version is always also updated. Currently if a migration succeeds but a
later migration doesn't, the changes of the migration apply but the
version stays - if the migration is breaking/non-idempotent, it will
fail when it tries to rerun it next time (otherwise it's just a
pointless re-execution).

Unfortunately with the current `db.runScripts` it wasn't that easy to
do, so I had to do quite a bit of refactoring. I am also ensuring the
right order of transactions now, though I assume that was already the
case lexicographically - can't hurt to be safe.
This commit is contained in:
Simon Frei
2025-08-30 13:18:31 +02:00
committed by GitHub
parent 2306c6d989
commit 4459438245
2 changed files with 68 additions and 27 deletions

View File

@@ -2,7 +2,8 @@ These SQL scripts are embedded in the binary.
Scripts in `schema/` are run at every startup, in alphanumerical order.
Scripts in `migrations/` are run when a migration is needed; the must begin
Scripts in `migrations/` are run when a migration is needed; they must begin
with a number that equals the schema version that results from that
migration. Migrations are not run on initial database creation, so the
scripts in `schema/` should create the latest version.
migration. Only one script per schema version must exist.
Migrations are not run on initial database creation, so the scripts in `schema/`
should create the latest version.