chore(db): add migration for missing lotw_credentials.name column#207
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the 500 error on
POST /api/lotw/certificatefor existing prod installs. The certificate-upload route INSERTs intolotw_credentials.name, but installs bootstrapped before the canonical baseline don't have that column — the install-flow backfill marks0000_baseline_canonical_schemaas 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.nameis the only one missing.Strategy
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-onlyof prod, seeded with:A pre-existing
lotw_credentialsrow (noname)drizzle.__drizzle_migrationspopulated to simulate the install-flow backfill statenpm run db:migrateruns cleanlynamecolumn added, set to NOT NULLPre-existing row backfilled with
W5TEST - LoTW CertificateTracking table gets a 4th entry
Second
npm run db:migrateis a no-opAfter deploy + migrate on prod:
POST /api/lotw/certificatesucceeds with a valid .p12 fileDeploy
Same as #204. After merge:
Expect
migrationsAppliedCount: 1. Then retry the LoTW certificate upload.🤖 Generated with Claude Code