feat(db): adopt prisma migrate for a real migration history - #67
Merged
Conversation
Replaces the `db push` dev workflow with committed migrations, so a clone comes up with a schema built from versioned SQL rather than a schema diff applied at boot. - prisma/migrations/20260826022052_init holds the initial migration, generated from the current schema - both compose stacks apply pending migrations with `migrate deploy` on start; a schema change is turned into a migration inside the running container (`docker compose exec app npx prisma migrate dev --name x`), so the host still needs no Node - CI gains a `migrations` job that applies the migrations to a real Postgres and fails when they have drifted from schema.prisma, catching a schema edit committed without its migration Also fixes two pre-existing defects this work uncovered: - docker-compose.prod.yml passed `db push --skip-generate`, a flag Prisma 7 removed, so the migrate service always exited 1 and the prod stack could never start - both compose files resolved to the same project name, sharing the `slipway-app` image tag and the `slipway_pgdata` volume: building the prod stack replaced the dev image, which carries the Prisma CLI the slim runner lacks, and `down -v` dropped the dev database. The prod stack is now its own project, `slipway-prod` Verified with lint, tsc, vitest and build; a clean and a repeat `docker compose up`; the prod stack end to end; and the CI job's drift detection.
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.
Replaces the
db pushdev workflow with committed migrations, so a clone comesup with a schema built from versioned SQL rather than a schema diff applied at
boot. This closes the last "not shippable" gap in the database story: there is
now a real migration history to deploy.
What changes
prisma/migrations/20260826022052_init— the initial migration, generatedfrom the current schema.
RateLimit.expiresAtkeeps itsTIMESTAMPTZ(3), andthe account/session foreign keys keep
ON DELETE CASCADE.migrate deployon start,so a fresh clone comes up migrated.
migrate deployis non-interactive andidempotent;
migrate devis not, and would try to reset a drifted database.the host still needs no Node:
migrationsapplies the migrations to a real Postgres, thenruns
migrate diff --exit-codeagainstschema.prisma. A schema editcommitted without its migration exits 2 and fails the job.
teaches
db push.Two pre-existing defects fixed along the way
docker-compose.prod.ymlpasseddb push --skip-generate, a flag Prisma 7 removed, so themigrateservicealways exited 1 and
appnever metservice_completed_successfully. No CIpath exercised the prod compose file, so this went unnoticed since the
Prisma 7 upgrade.
name
slipway, so they shared theslipway-appimage tag and theslipway_pgdatavolume. Building the prod stack replaced the dev image — andthe slim runner has no Prisma CLI, so the next dev start fell back to fetching
an unpinned
prismaprerelease from the registry.down -von prod alsodropped the dev database. The prod stack is now its own project,
slipway-prod.Verification
npm run lint,npx tsc --noEmit,npm run test(23 passed),npm run builddocker compose up: migration applied, app 200-v:No pending migrations to apply., app 200migrateexits 0, app 200migrate diffexit 2--build, the dev image digest is unchanged anddown -vremoves onlyslipway-prod_pgdataNote for after merge
The new
migrationsjob has to be added to the branch protection rule as arequired status check; it is not one automatically.