Demo, all content is generated
Question

prisma migrate dev wants to reset my Supabase database: drift detected

Solved · 1341 views · asked by hugo_l · edited
Drift detected: Your database schema is not in sync with your migration history.
...
We need to reset the "public" schema at "aws-0-eu-central-1.pooler.supabase.com:5432"
Do you want to continue? All data will be lost.

This is my only (production) database. Some tables were created by Supabase tutorials in the SQL editor before I added Prisma.

What I’ve tried

Said no, obviously. Claude Code suggested prisma db push --accept-data-loss, which also sounds bad.

Comment
Good instinct twice. Neither of those. kofi_mensah · edited

3 answers

Marked as helpful by the asker
rafa_dev · edited

migrate dev is a development command: it wants a disposable database. Never point it at production. What you need is a baseline: tell Prisma "the current state is migration 0".

npx prisma db pull                      # schema.prisma matches the DB
mkdir -p prisma/migrations/0_init
npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > prisma/migrations/0_init/migration.sql
npx prisma migrate resolve --applied 0_init

From then on: migrate dev against a local database (Docker or supabase start), migrate deploy against production. Set directUrl to the session pooler or direct connection for migrations.

Also leave Supabase's own schemas (auth, storage) out of Prisma's hands. If you reference auth.users, use the schemas preview feature carefully, or just keep a plain uuid column without a Prisma relation to it.

Comment
Baseline done, migrate status says up to date. And I now have a local db for migrate dev. Feels like a real developer lol hugo_l · edited
kofi_mensah · edited

Before any of this: take a dump (supabase db dump) so you have a way back. Takes a minute.

Comment
jonas_k · edited

Other approach: keep Supabase migrations (the supabase/migrations folder) as the source of truth and only use prisma db pull to generate the client. Then Prisma never migrates anything. Works well if you use RLS, which Prisma migrations don't know about anyway.

Comment
Also a fine setup, especially with RLS policies that Prisma can't express. rafa_dev · edited