Apply Prisma migrations on deploy #35
Merged
+109
−18
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.
Problem
The deploy workflow ran
prisma db push, which syncs tables but never executes migration SQL. SQL-only migrations (thehaversine_distancefunction) were therefore never applied, and no_prisma_migrationshistory was created. Any laterprisma migrate deploycould not recover from that state, and the deployed database was left without the function.Changes
pnpm db:deploy(prisma migrate deploy) instead ofprisma db push.db:deployscript to the root andpackages/dbpackage scripts.scripts/baseline-db.sh(pnpm db:baseline), a one-time bootstrap for databases that were created withdb push. It marks schema migrations that are already reflected in the database as applied and leaves SQL-only migrations pending somigrate deployruns them. It is idempotent and does nothing on an empty database or when migration history already exists.Testing
pnpm typecheckpnpm checkbash -n scripts/baseline-db.shprisma migrate deployappliedadd_reviews, the database was seeded, and the nearby/venue GraphQL queries (including reviews) return data again.