Skip to content

chore(db): add migration for missing lotw_credentials.name column#207

Merged
patrickrb merged 1 commit into
mainfrom
chore/migration-lotw-credentials-name
May 11, 2026
Merged

chore(db): add migration for missing lotw_credentials.name column#207
patrickrb merged 1 commit into
mainfrom
chore/migration-lotw-credentials-name

Conversation

@patrickrb
Copy link
Copy Markdown
Owner

Summary

Fixes the 500 error on POST /api/lotw/certificate for existing prod installs. The certificate-upload route INSERTs into lotw_credentials.name, but installs bootstrapped before the canonical baseline don't have that column — the install-flow backfill marks 0000_baseline_canonical_schema as already-applied without verifying every column exists (same root cause as #204).

Verified by full column-by-column diff between prod's schema and drizzle/migrations/0000_baseline_canonical_schema.sql — 284 columns each, lotw_credentials.name is the only one missing.

Strategy

ALTER TABLE lotw_credentials ADD COLUMN IF NOT EXISTS name varchar(255);
UPDATE lotw_credentials SET name = CONCAT(callsign, ' - LoTW Certificate') WHERE name IS NULL;
-- SET NOT NULL only if currently nullable (idempotent)
ALTER TABLE lotw_credentials ALTER COLUMN name SET NOT NULL;

Backfill rule keeps any pre-existing rows compliant with the NOT NULL constraint without losing data. Users can rename certificates via the UI afterward.

Test plan

Tested locally against a postgres container loaded with pg_dump --schema-only of prod, seeded with:

  • A pre-existing lotw_credentials row (no name)

  • drizzle.__drizzle_migrations populated to simulate the install-flow backfill state

  • npm run db:migrate runs cleanly

  • name column added, set to NOT NULL

  • Pre-existing row backfilled with W5TEST - LoTW Certificate

  • Tracking table gets a 4th entry

  • Second npm run db:migrate is a no-op

  • After deploy + migrate on prod: POST /api/lotw/certificate succeeds with a valid .p12 file

Deploy

Same as #204. After merge:

fetch('/api/admin/migrate', { method: 'POST' })
  .then(r => r.json().then(j => ({ status: r.status, body: j })))
  .then(console.log)

Expect migrationsAppliedCount: 1. Then retry the LoTW certificate upload.

🤖 Generated with Claude Code

Existing installs bootstrapped before the canonical baseline are
missing lotw_credentials.name. The column is declared NOT NULL in
drizzle/schema.ts and the certificate upload route (src/app/api/lotw/
certificate/route.ts) INSERTs into it — so on prod, POST
/api/lotw/certificate returns 500 with the underlying error
"column 'name' of relation 'lotw_credentials' does not exist".

Same root cause as 0002_add_propagation_tables: the install-flow
backfill marks 0000_baseline_canonical_schema as already-applied on
existing installs without verifying every column exists. A full
column-by-column diff between prod and canonical (284 columns each)
shows this is now the only remaining gap.

Strategy: add the column nullable first, backfill any existing rows
from callsign (`<CALLSIGN> - LoTW Certificate`), then SET NOT NULL.
The SET NOT NULL is wrapped in a DO block that checks
information_schema to make the migration safely idempotent.

Tested locally against a postgres container loaded with prod schema,
seeded with one pre-existing lotw_credentials row (no name) and with
drizzle.__drizzle_migrations populated to simulate the backfill state.
Migration runs cleanly; pre-existing row gets the auto-generated name;
column ends up NOT NULL; second run is a no-op.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nodelog Ready Ready Preview, Comment May 11, 2026 8:13pm

Request Review

@patrickrb patrickrb merged commit 08f96e8 into main May 11, 2026
7 checks passed
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