Skip to content

fix: Failed startup due to database migrations failure - #228

Open
EmmyKay0026 wants to merge 2 commits into
Vero-protocol:mainfrom
EmmyKay0026:fix/issue--fail-startup-on-migration-failure
Open

fix: Failed startup due to database migrations failure#228
EmmyKay0026 wants to merge 2 commits into
Vero-protocol:mainfrom
EmmyKay0026:fix/issue--fail-startup-on-migration-failure

Conversation

@EmmyKay0026

@EmmyKay0026 EmmyKay0026 commented Aug 25, 2026

Copy link
Copy Markdown

Summary

Closes #219

Prevents the API server and event worker from starting when database migrations fail. This avoids accepting webhook events or consuming queued jobs against an incomplete schema, which could cause silent loss of merged-PR registrations and retry records.

Changes

  • Updated startServer to log and rethrow database migration failures.
  • Ensured the HTTP server never binds its port unless migrations complete successfully.
  • Updated startEventWorker to fail startup when migrations fail.
  • Moved BullMQ worker creation until after successful migrations so jobs cannot be consumed prematurely.
  • Updated /health to return 503 DEGRADED whenever migration status is unknown or incomplete.
  • Added migration status to successful and degraded health responses.
  • Added regression tests covering:
    • API startup failure before port binding.
    • Worker startup failure before consumer creation.
    • 503 health response when migrations are incomplete.
    • 200 health response after successful migrations and a healthy database.

Verification

node --test --require ./test/global-teardown.js test/startup-migrations.test.js
npm test
node --check index.js
node --check src/workers/event-worker.js
node --check test/startup-migrations.test.js
git diff --check

Focused regression tests passed:
tests 4
pass 4
fail 0

The full test suite passed 250 of 258 tests. The remaining eight failures were existing PostgreSQL integration tests that require valid external database credentials and failed with a SCRAM password configuration error.

Security notes

  • No authentication, authorization, secret handling, or key-management behavior was changed.
  • Startup now fails closed when database schema readiness cannot be established.
  • This prevents webhook traffic and queued jobs from being processed without the required retry-state persistence.

Notes

  • Deployments with an unreachable database or failed migration will now exit non-zero and should be restarted or withheld from traffic by the orchestrator.
  • No partial-degradation environment flag was introduced; migration failure is intentionally treated as fatal.
  • A correctly configured PostgreSQL instance is required to run the complete integration-test suite.
image

N-thnI
N-thnI previously approved these changes Aug 27, 2026
@N-thnI

N-thnI commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

This branch now conflicts with main. Could you rebase onto the latest main and resolve the conflicts? Happy to merge once it's clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fail startup when database migrations fail instead of logging and continuing

2 participants