P
Prisma2mo ago
foxyyy

Migrate to Prisma Postgres

How is the easiest way to migrate my current postgres to a prisma postgres (already use prisma as orm)? Is there a way to import a backup file or whatever?
6 Replies
Prisma AI Help
Prisma AI Help2mo ago
You chose to compile with the bot. One moment while I piece together your answer… The easiest way to migrate your current PostgreSQL database to Prisma Postgres—when you’re already using Prisma ORM—is as follows: 1. Back up your existing PostgreSQL database
Use pg_dump to export your data:
pg_dump -Fc -v -d __DATABASE_URL__ -n public -f db_dump.bak

pg_dump -Fc -v -d __DATABASE_URL__ -n public -f db_dump.bak

Replace __DATABASE_URL__ with your current database connection string. This creates a backup file (db_dump.bak) of your data Import data from an existing database. 2. Create a new Prisma Postgres database
In the Prisma Console, create a new Prisma Postgres instance and get its connection string. 3. Connect to Prisma Postgres using a tunnel
Set your new Prisma Postgres connection string as an environment variable:
export DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=YOUR_API_KEY"

export DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=YOUR_API_KEY"

Then run:
npx @prisma/ppg-tunnel --host 127.0.0.1 --port 5432

npx @prisma/ppg-tunnel --host 127.0.0.1 --port 5432

Keep this process running Import data into Prisma Postgres. 4. Restore your backup into Prisma Postgres
In a new terminal, run:
PGSSLMODE=disable \
pg_restore \
-h 127.0.0.1 \
-p 5432 \
-v \
-d postgres \
./db_dump.bak \
&& echo "-complete-"

PGSSLMODE=disable \
pg_restore \
-h 127.0.0.1 \
-p 5432 \
-v \
-d postgres \
./db_dump.bak \
&& echo "-complete-"

This imports your data into Prisma Postgres. 5. Update your Prisma project
- Update your .env file with the new Prisma Postgres connection string. - Install the Accelerate extension:
npm install @prisma/extension-accelerate

npm install @prisma/extension-accelerate

- Extend your Prisma Client:
import { withAccelerate } from '@prisma/extension-accelerate'
const prisma = new PrismaClient().$extends(withAccelerate())

import { withAccelerate } from '@prisma/extension-accelerate'
const prisma = new PrismaClient().$extends(withAccelerate())

- Re-generate Prisma Client:
npx prisma generate --no-e
ngine

npx prisma generate --no-e
ngine

Update your application code That’s it! Your app will now use Prisma Postgres.
Nurul
Nurul2mo ago
Hey @foxyyy! Was the bot response helpful? Please let me know if you face any issues while trying to migrate to Prisma Postgres
foxyyy
foxyyyOP2mo ago
yes he was although I did not yet started as I'm still unsure if I want to migrate (currently deciding between prisma and neon)
foxyyy
foxyyyOP2mo ago
https://x.com/prisma/status/1951266173796098382 ok I guess the decision has answerd itself.
Prisma Postgres (@prisma)
Prisma Postgres is now 5x cheaper, what will you build next? See the new pricing👇 https://t.co/VNMnMoEmDA
From Prisma Postgres (@prisma)
X
foxyyy
foxyyyOP2mo ago
bdw Are there any plans for database branching or creating an identical copy of your actuall database with prisma dev?
Nurul
Nurul4w ago
Yes, we want to add support for branching in future

Did you find this page helpful?