Prisma - SQL Server - Wrong catalog - prisma

I'm trying to initialize the database with Prisma using the following command:
npx prisma migrate dev --name init
However, it complains that my database is not in sync and shows me table names from another database and ask if I want to reset it.
Here is the schema:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}
model Test {
id Int #id #default(autoincrement())
}
And the connection string:
sqlserver://localhost\SQLEXPRESS;initialCatalog=sample;integratedSecurity=true;trustServerCertificate=true;
The catalog "sample" is defined there, but for some reason, it is trying to connect to another existing database.
I tried to create the "sample" database manually but it doesn't change anything.
What am I missing here ?

Ok I changed initialCatalog to database and it's working.
sqlserver://localhost\SQLEXPRESS;database=sample;integratedSecurity=true;trustServerCertificate=true;

Related

Prisma migrate command gets stuck

I am trying to use Prisma with a local instance of Supabase running on docker. I created a very basic model inside prisma/schema.prisma file:
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DB_URL")
}
model Post {
id String #id #default(uuid())
title String
}
I also have the DB_URL variable in the .env file:
DB_URL="postgresql://postgres:postgres#localhost:54322/postgres"
When I run npx prisma migrate dev --name init to create a migration, I get the following message on the console and the process just runs without any result until I break it.
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "localhost:54322"
Am I missing something? Any ideas?
I resolved the problem by using ShadowDatabaseUrl

Prisma DB Can't connect to AWS RDS

I have a nextjs project that's using prismaDB for the ORM. I'm able to connect just fine to my local postgres db but I'm getting this error when running npx prisma migrate.
Error: P1001: Can't reach database server at db-name.*.us-west-2.rds.amazonaws.com:5432.
schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
//url = "postgresql://master_username:master_password#aws_host:5432/db_name"
}
The RDS db is currently public and I'm positive that I've copied over the RDS credentials correctly. There doesn't seem to be anything I should be including for the connection to work but I'm not getting any other info as to why I can't reach the db server.
Seems like you have to replace db-name.*.us-west-2.rds.amazonaws.com with the name of your actual database, unless you replaced it for the purpose of asking this question. Specifically the part where it says db-name.*.
Docs: https://www.prisma.io/docs/reference/api-reference/error-reference#common
P1001 indicates that it couldn't find the database given the connection string, NOT necessarily that the credentials you provided were wrong. Make sure you're specifying the correct database name/host and whatever else you need to make it work for AWS.
Somehow I was able to connect to RDS after deleting and creating a new DB for the third time. I confirmed connection through pgAdmin then tried it again my app deployed to vercel.

Getting "The 'mongodb' provider is not supported with this command" Error when try to do mongoDB migrate with Prisma

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

Prisma export database & models

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

Creating a database and collection programmatically for Azure Cosmos DB via Mongo DB .NET Driver

I am using the .NET MongoDb driver and Azure Cosmos DB Emulator. I am trying to create a database and collection on startup of a dotnet core Web Api project.
I am running the following code within the ConfigureServices function in Startup.cs.
var connectionString = databaseConfig.GetValue<string>("connectionString");
var databaseName = databaseConfig.GetValue<string>("name");
var client = new MongoClient(connectionString);
var db = client.GetDatabase(databaseName);
var collection = db.GetCollection("users");
This is neither creating the database or the collection. I am viewing this in the emulator's data explorer and Robo3T client.
I was under the impression that client.GetDatabase(databaseName) and db.GetCollection<User>("users") will create if the database and collection does not exist respectively.
I can get it to create the database and collection with the following db.CreateCollection("users"). This will require me to check if the collection first exists and isn't the prescribed approach.
Does anyone have any insights into this behaviour?
Thanks.
If you insert a document, the collection gets created, don't ask why!