fix(startup): make migration failure fatal instead of warn-and-continue #219
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/pms-286-fatal-migrations"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Makes a startup migration failure fatal instead of warn-and-continue. Closes PMS-286.
main.rslogged a failed migration at WARN and kept booting, serving a half-migrated database. This is how the staging outage happened: migration 040 (the PMS-263 co-mingled-rows verification) RAISED every boot, but because it was only a WARN the binary kept starting and never reached a healthy serving state - the container wentunhealthy, Traefik's Docker provider dropped themokosh-serverrouter, and every/api/v1request 404'd with no hint at the real cause. Later migrations (041, RLS coverage) silently never applied.Change
ERROR-level log + return from
main(which already returnsResult<_, Box<dyn Error>>) → process exits non-zero. Consistent with the rest of the startup path, which already hard-fails on SMTP / Google OAuth /ENCRYPTION_KEY/CORS_ORIGINmisconfiguration.RUN_MIGRATIONS=falsestill skips the migration step entirely; no new env var.Verification
cargo fmt --all --checkclean;cargo clippy --bin mokosh-serverclean; compiles.AC #4 - manual repro (no automated test)
main()is the binary entrypoint and not unit-testable, and a real migration failure cannot be forced under#[sqlx::test](every migration is applied clean before the test body runs), so this is documented rather than asserted by a test:RUN_MIGRATIONS=true.ERROR ... Failed to run database migrations: ...and the process exits non-zero.Database migrations complete, never binds, and/api/v1/healthis unreachable - vs. the old behaviour where it logged a single WARN, bound, and served unhealthy.Clear the co-mingled rows (or set
RUN_MIGRATIONS=false) and startup proceeds normally.