Skip to content

PM-5846: apply database migrations before API startup - #2

Merged
jmgasper merged 1 commit into
developfrom
PM-5846
Aug 12, 2026
Merged

PM-5846: apply database migrations before API startup#2
jmgasper merged 1 commit into
developfrom
PM-5846

Conversation

@jmgasper

Copy link
Copy Markdown
Contributor

What was broken

Closed ticket owners received a 500 Internal Server Error when submitting a reply, while replies to open tickets continued to work.

Root cause

The deployed reopen path writes notification outbox rows with the TICKET_REOPENED PostgreSQL enum value. That value is introduced by a Prisma migration, but the production container started the API directly and depended on a manual one-off migration. When application code was deployed ahead of the database migration, PostgreSQL rejected the reopen transaction and Nest returned a generic 500.

What was changed

  • Added a production startup script that runs prisma migrate deploy before starting the API.
  • Made startup fail safely if a pending migration cannot be applied.
  • Updated the Docker image to invoke the migration-aware startup script.
  • Updated deployment documentation to describe automatic migrations and concurrent-task safety.

Any added/updated tests

  • Added startup regression coverage verifying the production image invokes the startup script.
  • Verified migrations run before Node starts.
  • Verified a migration failure prevents the API from starting.
  • Ran the full test suite: 51 tests passed.
  • Ran pnpm lint, pnpm build, sh -n appStartUp.sh, git diff --check, and docker build --check . successfully.

A full Docker image build was also attempted twice, but both attempts stopped in the pre-existing Alpine package-install layer because dl-cdn.alpinelinux.org returned transient DNS errors. No changed Docker layer failed.

What was broken
Closed ticket owners received a 500 response when replying because the reopen transaction depended on a database enum migration that deployments could leave unapplied.

Root cause
The production container started the API directly and relied on a manual one-off Prisma migration. The deployed reopen path writes TICKET_REOPENED notification rows, so schema drift caused PostgreSQL to reject the transaction.

What was changed
The production startup now runs prisma migrate deploy before launching the API and stops if migration fails. Deployment documentation now describes the automatic startup migration behavior.

Any added/updated tests
Added startup regression coverage that verifies the production image uses the startup script, migrations run before Node, and the API does not start after a migration failure. All 51 tests, lint, build, shell syntax, and Dockerfile checks pass.
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.

1 participant