What's the best practice for deploying migrations to an existing database without syncing schema to prisma? #29524
QuestionBackgroundMy team is working on a new backend application for our multi-tenant platform. We have existing DBs (one per tenant) in mysql and we'd like our new application (which uses prisma) to reuse these DBs. There are tradeoffs for this approach which we are willing to accept because we'd like to isolate our customers' data to a single DB and take advantage of our existing infrastructure around that. The new application will only talk to the tables it knowns about and will never query the already existing tables, and vice versa. We were hoping to only define the new tables in the prisma schema and for the shared DBs to be an implementation detail that the app doesn't need to know too much about. The problem with this is when we run We don't want to pull down the schema because we don't want this new application to know anything about it and introduce the risk of someone querying tables from the old application. Also, we don't want to maintain the schema in two different places. QuestionWe realized one workaround is to create the How to reproduce (optional)
Expected behavior (optional)No response Information about Prisma Schema, Client Queries and Environment (optional)
|
Replies: 1 comment
|
I would not manually create
For your case, since you intentionally do not want Prisma to model the legacy tables, I would use a no-op baseline migration for each existing tenant DB, then let Prisma manage only the new tables from that point forward. Rough shape: mkdir -p prisma/migrations/0_existing_database_baseline
printf '%s\n' '-- Baseline existing tenant database. Legacy tables are intentionally unmanaged by Prisma.' \
> prisma/migrations/0_existing_database_baseline/migration.sql
npx prisma migrate resolve --applied 0_existing_database_baseline
npx prisma migrate deployRun the After that, future migrations that create/change only your Prisma-owned tables should deploy normally. A few caveats:
Docs:
|
I would not manually create
_prisma_migrations. The supported version of that idea is to baseline the existing database withprisma migrate resolve --applied.P3005is Prisma Migrate saying: "this database is not empty, but I have no migration history for it yet." That is expected for an existing production/tenant database.For your case, since you intentionally do not want Prisma to model the legacy tables, I would use a no-op baseline migration for each existing tenant DB, then let Prisma manage only the new tables from that point forward.
Rough shape: