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.
Related
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'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)
I started using prisma especially for handling database migrations. It handles that well. But there are many open issues for things that it does not handle well related to queries (biggest are related to queryRaw not always working as expected and with no straight forward way to use postgreSQL Row Level Security). Everything I've found to be a problem related to queries in prsima can easily be done in node-postgres.
I realize from the docs that some of these issues are not a problem in knexjs but prisma has a more feature rich migration setup (automatic and can be customized).
Can I safely use prisma and node-postgres together? If so, how? For example use prisma for schema design and database migrations and use node-postgres for all my query logic?
Yes, you can safely use prisma and node-postgres together.
Your workflow will look like the following:
Create a Prisma Schema to define your models and underlying database tables.
Use the Prisma CLI (the prisma npm library) to run migrations to your database. This will generate the client in node_modules/.prisma/client directory, which you could optionally delete as you won't be using it.
Instead of using generated Prisma Client inside your node application, use the node-postgres library to run queries against the database in your application.
Since you're only using Prisma to make any kind of migration or changes to the database structure, there's no risk of your prisma schema not being synced with your database. On the off chance this does happen, you can always get it back in sync using prisma db pull.
Furthermore, since your application is not going to use Prisma client to connect to the database for running queries, node-postgres will handle the connection pool.
I have my Old postgres database which is not a cloud based. And I want to migrate the data from the old database to new database which is in aws.
So can this be done via dblink or what is the other best practises to do this.
You can migrate DBs to AWS via AWS Database Migration Service. It's fully managed tool to help you move your data from on premises to AWS. You can read more about it here: https://aws.amazon.com/dms/?nc=sn&loc=1.
I'm using Laravel 3 and MongoHQ database.
In some tutorials (example: http://codehappy.daylerees.com/authentication) I need to create Schemas and Migrations, but how to do this with NoSQL database? Or should I keep this step?
Laravel (Version 4&3) uses the Eloquent ORM for database work. (including Migrations and Schemas)
Currently Eloquent only supports four database systems: MySQL, Postgres, SQLite, and SQL Server.
With MongoHQ you can not create Migrations or Schemas.
Source: https://laravel.com/docs/database