46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
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();
|
|
});
|