ND-007: FTS migration 20260207200000_add_fts_search fails on fresh DB — prisma migrate deploy aborts (P3018/42703) #56
Labels
No labels
blocked:gate-fetch
blocked:gate-implement
blocked:needs-attention
blocked:needs-decision
blocked:needs-human
blocked:needs-local-checkout
blocked:no-changes
bug
feature-request
in-progress
needs-decompose
needs-triage
ops-task
quickfix
security/high
security/low
security/medium
triage-approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Mark/nodedesk#56
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
The ND-007 FTS migration
prisma/migrations/20260207200000_add_fts_searchcannot be applied to a fresh database.npx prisma migrate deployaborts withP3018/ Postgres error42703(column "searchVector" of relation "Client" does not exist). This breaks the documented deploy path —docker-compose.ymlrunsnpx prisma migrate deployon boot — and any fresh CI database setup.Found by post-deploy probe of issue #11 (ND-007). Kanban card:
t_c6ecfe15.Reproduction
nodedesk-test-pgcontainer) and create an empty scratch DB.Mark/nodedeskatmain, run:init,email, andmagic-linkmigrations apply, then20260207200000_add_fts_searchaborts:Actual behavior
Fresh-DB deploys fail at the FTS migration. The docker-compose boot command
npx prisma migrate deployand any fresh CI DB setup are broken.Expected behavior
The migration applies cleanly on a fresh database (column created, GIN indexes built), as well as on databases that already had the earlier trigger-based columns.
Root cause
The UP section of
migration.sqlcontains unguarded cleanup statements written for a DB that already had thesearchVectorcolumn from the earlier trigger-based attempt:On a fresh DB the column doesn't exist, so
ALTER COLUMN ... DROP EXPRESSIONraises42703. The subsequentDROP COLUMN IF EXISTS "searchVector"lines are correctly guarded; these four lines are not.Suggested fix
ALTER COLUMN "searchVector" DROP EXPRESSIONlines (the guardedDROP COLUMN IF EXISTSalready covers dropping the column), orDO $$ ... IF EXISTS ... $$).Then re-verify a clean
prisma migrate deployagainst a fresh DB.Secondary observation (performance)
A DB provisioned via
prisma db push(as was done for the current #52 work) gets thesearchVectorcolumns but no GIN indexes —db pushcannot create GIN indexes onUnsupported("tsvector")columns. Such a DB silently runs FTS with sequential scans, defeating the performance point of ND-007. Consider documenting thatdb pushis not a substitute formigrate deployfor this migration, or adding a post-push index step.References
t_c6ecfe15(post-deploy probe of Mark/nodedesk#11)prisma/migrations/20260207200000_add_fts_search/migration.sqlFixed by commit
d618eb0(pushed to main 2026-08-10). The four unguardedALTER COLUMN ... DROP EXPRESSIONcleanup statements were removed — on a fresh DB the searchVector columns do not exist, so they abortedprisma migrate deploywith P3018/42703. TheDROP COLUMN IF EXISTSstatements that followed already handle both fresh DBs (no-op) and databases carrying the earlier trigger-era columns (verified DROP COLUMN works directly on a generated column). Verified end-to-end: fresh scratch DB +npx prisma migrate deploy→ all 6 migrations apply cleanly. This also unblocks the docker-compose boot deploy path and the #43 deployment concern.Fix landed + verified (fixup lane)
The unguarded
ALTER COLUMN ... DROP EXPRESSIONstatements were removed in commitd618eb0(fix(#56): FTS migration fresh-DB abort; legacy .gitea workflow SHAs; drop .eslintignore), already onorigin/main. The migration now uses only guardedDROP COLUMN IF EXISTSfor cleanup.Verified fresh-DB acceptance test (2026-08-13):
nd-test-pg), fresh empty DBscratch56DATABASE_URL=postgresql://test:test@127.0.0.1:5544/scratch56 npx prisma migrate deploy→ exit 0, all 6 migrations applied including20260207200000_add_fts_searchsearchVectortsvector columns present on Client/System/Note/WorkLog; all 4 GIN indexes createdClosing as resolved.