prisma: `Drift detected: Your database schema is not in sync with your migration history` - every migration on Supabase
Bug description
Every time I make any change to my schema prisma has started resetting my entire database with the following statement (even though none of the referenced changes have been made):
Drift detected: Your database schema is not in sync with your migration history.
The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.
It should be understood as the set of changes to get from the expected schema to the actual schema.
[*] Changed the `pgcrypto` extension
[+] Added extensions
- pg_graphql
[+] Added extensions
- pg_stat_statements
[+] Added extensions
- pgjwt
[+] Added extensions
- pgsodium
[+] Added extensions
- supabase_vault
[+] Added extensions
- uuid-ossp
? We need to reset the "public" schema at
How to reproduce
Here’s the relevant portion of my prisma schema:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [pgcrypto]
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch", "postgresqlExtensions"]
}
Expected behavior
As before, non destructive changes to my schema should not trigger a drift.
Prisma information
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [pgcrypto]
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch", "postgresqlExtensions"]
}
model Account {
id String @id @default(nanoid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(nanoid())
sessionToken String @unique
userId String
expires DateTime
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
Environment & setup
- OS: macOS
- Database: PostgreSQL (Supabase)
- Node.js version: lts/gallium v16.20.0
Prisma Version
prisma : 4.12.0
@prisma/client : 4.12.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine 659ef412370fa3b41cd7bf6e94587c1dfb7f67e7 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 659ef412370fa3b41cd7bf6e94587c1dfb7f67e7 (at node_modules/@prisma/engines/migration-engine-darwin)
Format Wasm : @prisma/prisma-fmt-wasm 4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7
Default Engines Hash : 659ef412370fa3b41cd7bf6e94587c1dfb7f67e7
Studio : 0.483.0
Preview Features : fullTextSearch, postgresqlExtensions
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 19
- Comments: 35 (7 by maintainers)
Solved by disabling all the extensions I could in the Supabase dashboard and adding the following migration to the
migrationsdirectory manually:While in the
schema.prisma:I tried some things today:
Using the following schema
first
migrate devsecond run, reduces the number of extensions added in the drift
Trying to add these 2 last extensions and schemas is not doable,
migrate devwill need to reset these, and I think that they are not supposed to be migrated / reset by anyone and should only be managed by Supabase.I tried to deactivate extensions from https://app.supabase.com/project/ljoyzzvkboexvsemukhj/database/extensions but pgsodium cannot be deactivated
I need to talk to some colleagues about this, my first thought is that Migrate needs, somehow to ignore these Supabase specific schemas (vault, pgsodium) at least, and maybe more?
Looking for a production level solution here too we’re trying to use the vector extension and running into this issue during migrate dev
Notes: I could reproduce this easily with
4.14.0When starting a fresh project db on supabase With the following schema:
running
npx prisma migrate devoutputs like in this issueThis drift shows in both cases: if the schema was changed or not. The reset, if saying yes, will be successful but needs to be done every time
migrate devis called which is not expected.npx prisma db pullonly addsextensions = [uuid_ossp(map: "uuid-ossp", schema: "extensions")]So now, how to solve this 🤔 ?
I think the problem is on Prisma Migrate side when
postgresqlExtensionsis enabled. Regardless of ifmultiSchemais enabled, Migrate will look in all schemas for extensions during the drift detection.Suggestion: Only check the current schemas for extensions for drift detection, meaning:
multiSchema, the schema defined in the connection URL or default (public)multiSchema, the schemas defined in the datasource propertyschemas = ["public", "something"]Then on Supabase, it should be possible to use the following schema:
Which would mean ignoring the schemas not present in the schemas property.
Current list of all schemas on Supabase:
that resolved my life here, thank you
I solved it this way:
Add extensions manually in extensions=[…], then do prisma db pull, this will fill out the extensions with the appropriate schema, then add the missing schemas to schemas=[…]
If a migration fails, check which extension made it fail and repeat the process above until there are no more extension left to add in prisma schema
I have added pg_trgm that is not by default on supabase
Your solution almost works for me, but I always keep getting_
Is there a solution for this? It’s been a pain in the **s for weeks!
I had to add another custom migration along with the above instructions.
I’m using vectors too, so can’t get rid of the
postgresqlExtensions.The only reliable workaround I found is to add new columns/tables directly in the database then use
npx prisma db pull && npx prisma generateI find from documentation. link
doesn’t sync db with schema. why?