x
This commit is contained in:
1 parent
684fd6907b
commit
310e48fe6a
17 files changed
+424
-139
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import prisma from '../src/lib/prisma';
|
||||
|
||||
async function main() {
|
||||
console.log('Starting i18n migration...');
|
||||
|
||||
const products = await prisma.product.findMany();
|
||||
console.log(`Found ${products.length} products to migrate.`);
|
||||
|
||||
for (const product of products) {
|
||||
const existingTranslation = await prisma.productTranslation.findUnique({
|
||||
where: {
|
||||
productId_langCode: {
|
||||
productId: product.id,
|
||||
langCode: 'th',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!existingTranslation) {
|
||||
await prisma.productTranslation.create({
|
||||
data: {
|
||||
productId: product.id,
|
||||
langCode: 'th',
|
||||
name: product.name,
|
||||
description: product.description,
|
||||
details: product.details,
|
||||
},
|
||||
});
|
||||
console.log(`Created Thai translation for product ID: ${product.id}`);
|
||||
} else {
|
||||
console.log(`Thai translation already exists for product ID: ${product.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Migration completed successfully.');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in new issue
Block a user