61 lines
1.3 KiB
TypeScript
61 lines
1.3 KiB
TypeScript
import prisma from '../lib/prisma';
|
|
|
|
async function main() {
|
|
console.log('Migration started...');
|
|
|
|
// 1. Kategorileri Güncelle
|
|
const categories = await prisma.categories.findMany();
|
|
console.log(`Found ${categories.length} categories.`);
|
|
|
|
for (const cat of categories) {
|
|
const name_i18n = {
|
|
en: cat.name,
|
|
tr: cat.name_tr
|
|
};
|
|
|
|
await prisma.categories.update({
|
|
where: { id: cat.id },
|
|
data: {
|
|
name_i18n: name_i18n
|
|
}
|
|
});
|
|
}
|
|
console.log('Categories migrated.');
|
|
|
|
// 2. Ürünleri Güncelle
|
|
const products = await prisma.products.findMany();
|
|
console.log(`Found ${products.length} products.`);
|
|
|
|
for (const prod of products) {
|
|
const name_i18n = {
|
|
en: prod.name,
|
|
tr: prod.name_tr
|
|
};
|
|
|
|
const description_i18n = {
|
|
en: prod.description || '',
|
|
tr: prod.description_tr || ''
|
|
};
|
|
|
|
await prisma.products.update({
|
|
where: { id: prod.id },
|
|
data: {
|
|
name_i18n: name_i18n,
|
|
description_i18n: description_i18n
|
|
}
|
|
});
|
|
}
|
|
console.log('Products migrated.');
|
|
|
|
console.log('Migration completed successfully!');
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|