Summary
Automate keeping schema.sql canonical and lint migrations, so drift like the one fixed in #191 can never silently return.
Background & current behaviour
database/schema.sql was re-synced to the migration chain in #191 and the CI integration job now builds the test DB from migrations. But nothing prevents schema.sql from drifting again, and migrations aren't linted for idempotency/ordering/destructive patterns.
Why this matters for MVP
Schema drift caused real, silent breakage (audit_log/parse_errors missing from schema.sql). A CI guard makes the class of bug impossible going forward.
Proposed implementation
- In CI, spin up Postgres, apply the migration chain,
pg_dump --schema-only, normalise, and diff against a committed canonical dump; fail on divergence (or auto-regenerate schema.sql and fail if uncommitted).
- Add a migration linter: enforce
IF NOT EXISTS, forbid CONCURRENTLY inside a transaction, flag destructive statements (DROP, ALTER ... TYPE) for explicit review, enforce ordered numeric filenames.
- Document the "adding a migration" workflow.
Acceptance criteria
Affected files / components
.github/workflows/ci.yml
database/ (canonical dump + linter script)
Testing & verification
Introduce a deliberate drift in a test branch and confirm CI fails; a clean chain passes.
Related / dependencies
Follows up #191.
Out of scope
A migration framework change (stay with sqlx migrations).
Target branch
All work for this issue MUST target the dev branch. Cut your feature branch from dev and open the pull request against dev, never against main. Any PR opened against main for this issue will be closed and asked to re-target dev.
Summary
Automate keeping
schema.sqlcanonical and lint migrations, so drift like the one fixed in #191 can never silently return.Background & current behaviour
database/schema.sqlwas re-synced to the migration chain in #191 and the CI integration job now builds the test DB from migrations. But nothing preventsschema.sqlfrom drifting again, and migrations aren't linted for idempotency/ordering/destructive patterns.Why this matters for MVP
Schema drift caused real, silent breakage (audit_log/parse_errors missing from schema.sql). A CI guard makes the class of bug impossible going forward.
Proposed implementation
pg_dump --schema-only, normalise, and diff against a committed canonical dump; fail on divergence (or auto-regenerateschema.sqland fail if uncommitted).IF NOT EXISTS, forbidCONCURRENTLYinside a transaction, flag destructive statements (DROP,ALTER ... TYPE) for explicit review, enforce ordered numeric filenames.Acceptance criteria
Affected files / components
.github/workflows/ci.ymldatabase/(canonical dump + linter script)Testing & verification
Introduce a deliberate drift in a test branch and confirm CI fails; a clean chain passes.
Related / dependencies
Follows up #191.
Out of scope
A migration framework change (stay with sqlx migrations).
Target branch
All work for this issue MUST target the
devbranch. Cut your feature branch fromdevand open the pull request againstdev, never againstmain. Any PR opened againstmainfor this issue will be closed and asked to re-targetdev.