Public: anyone can read this; the crew can change it.

A database the app cannot open or upgrade no longer kills the server: it still listens, and /healthz answers 503 naming the step that failed #225

Closed opened this
Closed without merging

A database that fails to open or upgrade no longer kills the server. It still listens, and /healthz answers 503 naming the step that failed. What changed src/db.ts: openDb now runs migration, seed and sample refresh as named steps.

Notes

stopped closed without shipping deploy 1a76f84

opened this

A database that fails to open or upgrade no longer kills the server. It still listens, and /healthz answers 503 naming the step that failed.

What changed

  • src/db.ts: openDb now runs migration, seed and sample refresh as named steps. A failure throws an OpenError carrying the step name and SQLite's own message, and the connection is closed first. The migrations themselves are untouched, so #214's ground is clear.
  • src/server.ts: serve() catches that failure and logs one line: <title>: database cannot be opened at boot, step "migration" failed: <message>. It then starts a minimal server on the same port.

- /healthz answers 503 as plain text with the step and message, no stack. - Every other path answers 503 with a short page saying the app cannot open its records. - Both carry the security headers from src/http.ts, plus cache-control: no-store and retry-after: 60. - Nothing in that state writes to the database. The migration runs in a transaction, so a failure rolls back. A failed seed or sample refresh is left as SQLite leaves it, not repaired.

  • src/health.test.ts: a new test boots serve() on a directory whose schema_version records version 1 with no tables. It asserts that the server listens, /healthz is 503 and names migration, and / is 503 with the headers. It also checks the log line and that schema_version is unchanged afterwards.

Checked

  • bun test on src/health.test.ts, src/db.test.ts, src/server.test.ts and src/upgrade.test.ts: 121 pass. I did not run the full suite.
  • I did not run the new test against main to watch it fail. On main the boot throws before listening, so there is nothing for it to connect to.
  • bun x tsc --noEmit printed tsc's help text and checked nothing, because the repo has no tsconfig.json.
  • I did not run scripts/gate.ts, scripts/fast.ts or scripts/design-lint.ts: none exists in this clone, and src/web/ is untouched.

Left alone

  • /healthz echoes SQLite's message verbatim, as the issue asked. Those messages name tables and columns but not file paths.
  • I did not add retry or self-repair. That is #214.
  • The contract is unchanged, so no cell was loosened.

To try it, point serve() at a data directory whose app.db has a recorded schema version but a table missing, then curl -i /healthz and /.

Closes #222

commented

A database that fails to open or upgrade no longer kills the server. It still listens, and /healthz answers 503 naming the step that failed.

What changed

  • src/db.ts: openDb now runs migration, seed and sample refresh as named steps. A failure throws an OpenError carrying the step name and SQLite's own message, and the connection is closed first. The migrations themselves are untouched, so #214's ground is clear.
  • src/server.ts: serve() catches that failure and logs one line: <title>: database cannot be opened at boot, step "migration" failed: <message>. It then starts a minimal server on the same port.

- /healthz answers 503 as plain text with the step and message, no stack. - Every other path answers 503 with a short page saying the app cannot open its records. - Both carry the security headers from src/http.ts, plus cache-control: no-store and retry-after: 60. - Nothing in that state writes to the database. The migration runs in a transaction, so a failure rolls back. A failed seed or sample refresh is left as SQLite leaves it, not repaired.

  • src/health.test.ts: a new test boots serve() on a directory whose schema_version records version 1 with no tables. It asserts that the server listens, /healthz is 503 and names migration, and / is 503 with the headers. It also checks the log line and that schema_version is unchanged afterwards.

Checked

  • bun test on src/health.test.ts, src/db.test.ts, src/server.test.ts and src/upgrade.test.ts: 121 pass. I did not run the full suite.
  • I did not run the new test against main to watch it fail. On main the boot throws before listening, so there is nothing for it to connect to.
  • bun x tsc --noEmit printed tsc's help text and checked nothing, because the repo has no tsconfig.json.
  • I did not run scripts/gate.ts, scripts/fast.ts or scripts/design-lint.ts: none exists in this clone, and src/web/ is untouched.

Left alone

  • /healthz echoes SQLite's message verbatim, as the issue asked. Those messages name tables and columns but not file paths.
  • I did not add retry or self-repair. That is #214.
  • The contract is unchanged, so no cell was loosened.

To try it, point serve() at a data directory whose app.db has a recorded schema version but a table missing, then curl -i /healthz and /.

commented

Declined: I did not change the code, so nothing new is pushed. The preview failure is not caused by this pull, and the only fix is #214, which this issue told me to stay out of. Run log: https://forge.open-platform.sh/trevato/deal-clock/runs/01m6zcfqx91159b9na60ydjfnb

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs