Prisma export database & models - 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

Related

How to use database replication in prisma and nestjs

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.

How I can change data in prisma.schema, without losing data after migration?

When I changed prisma.schema and run:
npx prisma migrate dev --name init
My Postgres lost all data. Can I run another command which doesn't remove my data? What is best for me in this situation?
From the prisma.io documentation:
Prisma Migrate is an imperative database schema migration tool that enables you to keep your database schema in sync with your Prisma schema as it evolves and
main existing data in your database
Prisma Migrate generates a history of .sql migration files, and plays a role in both development and deployment.
This means that the prisma migrate command is supposed to be syncing the data from the model with the one in the database, adding/removing rows if needed, etc.
Perhaps the command you are looking for is prisma db push? They both have similar uses and aspects, one is for dev, one isn't.

Prisma migration fail with supabase

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)

How to export and import data from a Postgres database with Hasura?

I have Hasura GraphQL engine running on a Docker container. My goal is to export all the data from my Postgres database so that my coworker can import it and work with the same data. What is the correct way to do this with Hasura?
You can totally do like the normal database on docker, nothing different, you can use any kind of dump or import/export.
You should understand the way Hasura works, it just take database as an input, Hasura does not take the database installation process.

How to load a foodmart database in to postgres

i have installed a PostgreSQL database.Now i need to download and import a food mart database to practice some reporting techniques.I am new to this field so do not know where to start.Please it will be very helpful if anyone can provide me a guidance to start it.
This repo contains the foodmart data loader for Postgres, Mysql, Sqlserver, Sybase
https://github.com/OSBI/foodmart-data
All you need to do is clone it and launch the following script:
sh FoodMartLoader.sh --db postgres
connection props are set inside the script
For Clickhouse DB2 and SAP Hana and some other DBs look at the branches of this
fork:
https://github.com/contiamo/foodmart-data-public