Recommendation for data migration with prisma and mongodb
Hello, for data migration with prisma and mongodb, do you recommend the “No breaking changes updates” method, where you put the new optional fields (but if you need to update values, it doesn't work because the value is null) or the “”All-at-once“ updates:” method, where you add the new fields with a default value. In the latter case, what is recommended for migration scripts? Are we supposed to have a migration script that will automatically create the value thanks to the script? What should this script look like? If prisma's migrate method doesn't work with mongodb, do you have to write it manually?
Would this work for exemple : // scripts/addNewFields.js
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function runMigration() {
try {
// Example for the Customer model: add loyaltyPoints and isVIP
const result = await prisma.customer.updateMany({
data: {
loyaltyPoints: 0,
isVIP: false,
},
});
} catch (error) {
console.error('Migration error:', error);
process.exit(1);
} finally {
await prisma.$disconnect();
}
}
runMigration();
/*
=== package.json UPDATE ===
"scripts": {
"build": "remix vite:build",
"setup": "prisma generate && prisma db push",
"migrate:data": "node scripts/addNewFields.js",
"docker-start": "npm run setup && npm run migrate:data && npm run start",
...
}
Thanks a lot
Would this work for exemple : // scripts/addNewFields.js
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function runMigration() {
try {
// Example for the Customer model: add loyaltyPoints and isVIP
const result = await prisma.customer.updateMany({
data: {
loyaltyPoints: 0,
isVIP: false,
},
});
} catch (error) {
console.error('Migration error:', error);
process.exit(1);
} finally {
await prisma.$disconnect();
}
}
runMigration();
/*
=== package.json UPDATE ===
"scripts": {
"build": "remix vite:build",
"setup": "prisma generate && prisma db push",
"migrate:data": "node scripts/addNewFields.js",
"docker-start": "npm run setup && npm run migrate:data && npm run start",
...
}
Thanks a lot