MongoDB: (Data) Migration Support
See original GitHub issueProblem
Migrating your database over time is an important part of the development cycle. We offer some great tooling for SQL databases like Postgres and MySQL with prisma migrate
and db push
, but we don’t offer the same level of support for MongoDB.
There are a couple ways to migrate data with MongoDB:
-
On-Demand: When you add a new field to your schema, the past data isn’t touched. But when you go and read the collection, the collection is adjusted, so when you write the data back, your data now matches your schema.
- This is how ORMs like Mongoose work
-
No Breaking Change Policy
- Don’t rename or delete fields, only add fields.
- Typically these teams are very well aware of using MongoDB and it’s constraints. They may have checks in CI/CD to make sure they don’t have backwards-incompatible changes to the schema
-
All-at-Once: where you update your schema and your past data to match your new schema all at once
- This is a requirement of relational databases that all the data must match a specific schema, but not for NoSQL
- All at once is what you think of when you think of traditional migration systems.
Suggested solution
- We help you add, change and remove indexes
- We offer some way to migrate old data to a new schema. The All-at-Once Migration above.
Alternatives
We currently support On-Demand and No Breaking Change Policy migrations.
For All-at-Once Migrations you’d need to write a script that transforms your data.
References
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:7 (2 by maintainers)
Top GitHub Comments
Did anything came up about this topic? It would be awesome to prisma have a good integration with migrations.
For those looking for solutions, I’m using mongo-migrate-ts while prisma doesn’t add it.
@ajcwebdev there are currently no plans for migrations, because we haven’t seen a clear good solution yet. We’re going to merge and release https://github.com/prisma/prisma-engines/pull/2287 very soon though. The scope is only reflecting
@@index
and@@unique
declarations in the prisma schema into MongoDB indexes withdb push
.