I implemented this CLI because I had to migrate from a PostgreSQL database to a MySQL database for my startup Typebot. Prisma takes care of the data transformation and this allows you to migrate without downtime.
I just tested the scripts with my setup. You may have to tweak things for yours. Feel free to create an issue so that I can help 👌
@updatedAt or @createdAt). To avoid extracting all the data every time.You just have to provide 2 prisma schemas: source and target.
The first data sync will take some time because it will download all the data from the beginning. Then, subsequent syncs will be tiny and will happen in an instant.
.env.example to .env and fill it with your database URLs (It is recommended to disable the prisma pool timeout using the ?pool_timeout=0 query param).src/schemas/source.prisma and src/schemas/target.prisma with your schemas. Make sure it contains:generator utils {
provider = "pnpm tsx src/generatePrismaUtilsTypes.ts"
output = "prisma-clients/target"
}
pnpm installpnpm start, it will popup the menu
? › - Use arrow-keys. Return to submit.
❯ Sync - Watch for changes in your source database and inject it in your target database
Dump
InjectThis library has 3 functions dump, inject, sync:
dump reads your source database and generate timestamped snapshotsinject injects the previously imported snapshots chronologicallysync executes dump and restore with a set intervalThis is perfect if you are planning on migrating to another database in production. The first dump will be quite big as it will pull all the data from the beginning. Subsequent dumps will be tiny.
Let's say you need to migrate to a new database and can't afford to have application downtime:
It doesn't detect if a row has been deleted on the source database.
Foreign keys can make it difficult to sync data. Two options are:
If your target schema uses prisma relationMode (or if it's a MongoDB database), you need to set the relationMode to foreignKeys
$ claude mcp add prisma-database-sync \
-- python -m otcore.mcp_server <graph>