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
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
Prisma
Prisma will try to drop the db during the migration and SupaBase doesn't like that so Prisma requires you to make a "Shadow Database"
Prisma Docs: Shadow Databases
SupaBase
To create the shadow db and get its connection string you have to connect to the SupaBase db with psql, create a new database and modify your connection string to point to the new db. (because prisma IS allowed to delete this second db during migration)
SupaBase Docs: Prisma (Shadow db)
Related
I am connecting my existing database to Prisma. I am followed the documentation (https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/baseline-your-database-typescript-sqlserver). But the baseline step is throwing an error that is given below,
the command I tried is "npx prisma migrate resolve --applied 0_init". Anybody have the same issue?
Currently, I am working on a Nestjs project where I am using Prisma as ORM and MySql as database.
But I am stuck now when I tried to use database replication in this project.
Any help will be appreciated.
I'm developing some simple Todo App BE using NestJS with Prisma ORM and use MongoDB as the DB. I'm using a FREE and SHARED MongoDB cluster that is hosted in MongoDB Altas cloud. Also I added 0.0.0.0/0 to the network access tab so anyone can connect to the DB.
schema.prisma file
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Task {
id String #id #default(auto()) #map("_id") #db.ObjectId
name String?
description String?
status TaskStatus #default(TODO)
}
enum TaskStatus {
TODO
INPROGRESS
DONE
}
.env file
DATABASE_URL="mongodb+srv://<username>:<password>#todoappdb.jfo3m2c.mongodb.net/?retryWrites=true&w=majority"
But when I try to run npx prisma migrate dev --name init command it gives following output
D:\todoapp-backend>npx prisma migrate dev --name init
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db"
Error: The "mongodb" provider is not supported with this command. For more info see https://www.prisma.io/docs/concepts/database-connectors/mongodb
0: migration_core::state::DevDiagnostic
at migration-engine\core\src\state.rs:250
Can someone point me what is the problem?
After reading some content, found that prisma migrate commands are for the SQL databases only since they have a rigid table structure. But MongoDB is a document database and those data are unstructured
So rather than running prisma migrate command we can use following command
npx prisma generate
This command creates the Prisma client that gives type-safe access to our database.
Reference - https://www.youtube.com/watch?v=b4nxOv91vWI&ab_channel=Prisma
is there a way to create a dump of your database with the models, so that I can just push it on another database and just have to update my database address and all works out fine?
Exporting from Prisma CLI itself is not possible as of now.
But what you can do is dump the db from the postgres cli.
And then Import the dump in your new DB : Guide from Prisma
Connect to this DB in your new application add a schema.prisma with base configuration, without models and pull the DB: Introspection Guide from Prisma
I have the following code to generate the schema for a database in Nhibernate
new SchemaExport(configuration).Execute(true, true, false);
but when run against a PostgreSQL database, I end up getting the following error
[NpgsqlException (0x80004005): FATAL: 3D000: database "dbname" does not exist]
If I however create the database manually, the schema is exported without errors. An so the question: Why is Nhibernate SchemaExport unable to create a PostgreSQL database and yet this works against other databases like SQLite, MsSqlCe and MsSql Server.
I have searched for online literature but have been unable to locate any highlighting on this issue.
I am using Nhibernate 3.3.1 with PostgreSQL 9.2.
You must create the database before you can create the tables and other objects within the database.
Do this with a CREATE DATABASE statement on a PostgreSQL connection - either in your app, or via psql or PgAdmin-III.
PostgreSQL doesn't support creating databases on demand / first access. Perhaps that's what your tool is expecting?
If you think the DB does exist and you can see it in other tools, maybe you're not connecting to the same database server? Check the server address and port.