Migrate database from one to another.
Copy prisma/.env.sample
to prisma/.env
.
cp prisma/.env.sample prisma/.env
Add DATABASE_URL_OLD
, and DATABASE_URL
correct values as provided in Prisma datasource.
Finally, install packages and generate Prisma client.
bun install && bun generate
Since the repo uses Prisma, it supports database connectors as provided.
- PostgreSQL
- MySQL
- SQLite
- MongoDB
- CockroachDB
- Microsoft SQL Server
Open src/index.ts
and start writing migration script. The initial template looks like below.
import {PrismaClient} from './generated/client';
import {PrismaClient as PrismaClientOld} from './generated/client-old';
import fs from 'fs';
const prismaOld = new PrismaClientOld();
const prisma = new PrismaClient();
const logFileName = 'logFile.txt';
async function main(): Promise<void> {
}
main()
.catch((e) => {
fs.appendFile(logFileName, `main catch::${e}\n`, (err) => {
if (err) console.log(`File logging error: ${err}\n`);
});
process.exit(1);
})
.finally(async () => {
await Promise.all([
prismaOld.$disconnect(),
prisma.$disconnect()
]);
});
After you wrote the script, run
bun start
.