Implement the versioned migration runner #17

5 Commits
Author SHA1 Message Date
Joshua King f27c84488d fix: serialize concurrent migration runners with a per-connection lock
NestQuestDatabase rejects a second transaction while one is active, so
two concurrent apply_migrations callers on one connection crashed with
RuntimeError instead of queueing. apply_migrations now holds a
per-(connection, loop) asyncio lock across the whole decide-and-apply
span; the queued runner re-reads the stamped version and applies
nothing. Deterministic concurrent-runner regression test added.
2026-09-14 07:07:46 -04:00
Joshua King c0c540c194 fix: re-read schema version inside each migration transaction; spy on close in setup-failure test
- apply_migrations re-reads the version under the transaction lock
  before applying, so two interleaved runners on one connection cannot
  both apply a non-idempotent migration from a stale read
- setup-failure test now spies on NestQuestDatabase.close and asserts
  it ran and no runtime record was stored (was vacuous)
2026-09-14 07:05:13 -04:00
Joshua King a679004720 test: hash WAL alongside main db in no-op test; exercise unload+setup reload lifecycle 2026-09-14 07:01:49 -04:00
Joshua King 492c1149f0 fix: address review findings - startup wiring, singleton version table, version guards
- __init__.py now calls apply_migrations() on setup instead of raw DDL
  (HIGH finding: the runner was never invoked at startup); lifecycle
  wiring tests in test_migrations.py cover fresh migrate, reload reuse,
  and close-on-failure
- VERSION_TABLE DDL enforces singleton row (id=1 PRIMARY KEY + CHECK)
  and version >= 1; stamp is INSERT .. ON CONFLICT DO UPDATE keyed on
  the singleton row
- read_schema_version rejects non-integer and sub-1 versions with
  explicit guards (bool excluded)
- no-op test asserts content hash + mtime, not just size
2026-09-14 06:59:30 -04:00
Joshua King c6d42e8277 feat: add versioned schema migration runner (#17) 2026-09-14 06:54:45 -04:00