Reputation: 411
I'm trying to generate some migrations using Prisma.
I'm using Supabase which is using Postgres under the hood.
Also, I tried to run the following command with the local emulator and with the "real project".
When I run prisma db push
it's working, so the communication between prisma and supabase can be established.
But when I try to run prisma migrate dev
I get the following error
Error: db error: ERROR: no such database: prisma_migrate_shadow_db_b2ce3e4e-c5ef-41f6-830f-2203a082f1db
0: sql_migration_connector::flavour::postgres::sql_schema_from_migration_history
at migration-engine/connectors/sql-migration-connector/src/flavour/postgres.rs:367
1: migration_core::api::DevDiagnostic
at migration-engine/core/src/api.rs:108
Supabase CLI : 0.15.3
Prisma : 3.6.0
Upvotes: 1
Views: 5454
Reputation: 478
Error: db error: FATAL: bouncer config error
0: migration_core::state::DevDiagnostic
at migration-engine/core/src/state.rs:269
According to Prisma documentation, the prisma migrate
command requires second, temporary database called Shadow Database
in order to detect problems such as schema drift.
Some development-focused commands for relational databases of Prisma Migrate use a second, temporary database:
prisma migrate dev
prisma migrate reset
The shadow database is created and deleted automatically* each time you run a development-focused command and is primarily used to detect problems such as schema drift.
Therefore, Supabase needs to create additional DB temporarily.
According to the same doc if you are using a cloud-hosted database
for development, you need to create the shadow database manually.
create
another DB in Supabase Cloud.
copy
newly created Supabase Cloud URL
Add
new SHADOW_DATABASE_URL
field in .env
.
paste
Supabase Cloud URL
to SHADOW_DATABASE_URL
Add shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
in schema.prisma
:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}
save
files and run npx prisma db migrate
Upvotes: 0
Reputation: 725
Prisma Docs: Shadow Databases
SupaBase Docs: Prisma (Shadow db)
Upvotes: 0
Reputation: 411
I also asked this question on Prisma repo : https://github.com/prisma/prisma/issues/10575
The solution is to create a shadow database as mentionned in the documentation https://www.prisma.io/docs/concepts/components/prisma-migrate/shadow-database#cloud-hosted-shadow-databases-must-be-created-manually
Upvotes: 2