Skip to content

fix(db): run prisma migrate deploy on production builds - #22

Merged
CodeWithEugene merged 1 commit into
mainfrom
fix/prod-migration-pipeline
Sep 24, 2026
Merged

CodeWithEugene merged 1 commit into
mainfrom
fix/prod-migration-pipeline

Conversation

@CodeWithEugene

Copy link
Copy Markdown
Owner

Summary

Audited the full auth flow end-to-end after a report that verification emails weren't sending. Findings:

1. Verification emails: actually working now, root cause was timing. Live testing (real signup, resend, click-through, sign-in, all confirmed via Brevo's delivery events) shows send + resend both work correctly on the current deployment. The hackvillage.xyz domain's DNS authentication in Brevo only completed at 04:56 UTC today — any attempts before that would have had degraded or failed deliverability. No code change needed here; verified end-to-end.

2. Real bug found: /settings has been throwing 500 in production since PR #18. The 9_notification_preferences migration was merged and applied to the local dev DB and CI's ephemeral test Postgres, but next build's script only ran prisma generate — never prisma migrate deploy — so the table was never created on the actual production Neon database. Every request to /settings (account settings, password change, payout method, email preferences) has been crashing with P2021: table does not exist.

  • Applied the missing migration to production directly (prisma migrate deploy against the Neon prod DB) to fix it immediately — confirmed via live testing that /settings now loads, password change works and sends its confirmation email, and email preferences save correctly.
  • Fixed the pipeline gap so this can't recur silently: scripts/migrate-if-production.mjs now runs as part of pnpm run build, applying prisma migrate deploy only when VERCEL_ENV=production (preview and production share one Neon database, so this avoids an unmerged preview branch mutating prod schema before review).

3. Also verified while auditing: signup → verification → click-through → sign-in; forgot-password → reset → sign-in with new password; Google and GitHub OAuth both correctly reach their provider consent screens.

4. Small fix: centers the "Welcome Back" heading/subtitle on the sign-in card, matching the rest of the auth pages.

Test plan

  • pnpm run typecheck / pnpm run lint — clean
  • pnpm exec vitest run tests/unit — 98/98 passing
  • pnpm run build — confirms the new build script correctly skips migration locally (VERCEL_ENV unset) and still builds
  • Live end-to-end on production: signup, resend, email verification click-through, sign-in, forgot/reset password, settings password change + email, email preferences save — all confirmed via Brevo delivery events and direct DB checks
  • Test data cleaned up (temporary test account removed from production DB)

Auditing "verification emails not working" turned up a much bigger
issue: the 9_notification_preferences migration was merged in PR #18
but had only ever been applied to the local dev database and CI's
ephemeral test Postgres, never to the actual production Neon database.
`next build` never ran `prisma migrate deploy` — the app's build script
only ran `prisma generate` — so every request to /settings (account
settings, password change, payout method, email preferences) had been
throwing a 500 in production since that PR merged.

Applied the missing migration to production directly to fix it now,
and changed the build script so this can't silently happen again:
`scripts/migrate-if-production.mjs` runs `prisma migrate deploy` only
when `VERCEL_ENV=production` (preview and production share one Neon
database, so this avoids an unmerged preview branch applying its
migration before review).

Also centers the "Welcome Back" heading and subtitle on the sign-in
card, matching the rest of the auth pages.
@CodeWithEugene
CodeWithEugene merged commit d85be90 into main Sep 24, 2026
5 checks passed
@CodeWithEugene
CodeWithEugene deleted the fix/prod-migration-pipeline branch September 24, 2026 11:35
Repository owner deleted a comment from vercel Bot Sep 25, 2026

This branch was successfully deployed

1 active deployment
Preview — c3aac6be Deployed Sep 24, 2026 by vercel[bot]
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