fix(seed): deduplicate ingredients and symptoms to ensure clean database seeding
This commit is contained in:
parent
8a6afa10d8
commit
ddf2bafb3c
@ -256,28 +256,31 @@ export async function main() {
|
||||
}
|
||||
});
|
||||
|
||||
// Seed ingredients
|
||||
// Seed ingredients safely
|
||||
await prisma.productIngredient.deleteMany({ where: { productId: product.id } });
|
||||
if (cleanIngredients) {
|
||||
const parts = cleanIngredients.split(/[،,]/).map((s: string) => s.trim()).filter(Boolean);
|
||||
const meaningful = parts.slice(0, 20);
|
||||
for (const ing of meaningful) {
|
||||
const truncated = ing.substring(0, 150);
|
||||
const uniqueIngredients = Array.from(new Set(parts.map(ing => ing.substring(0, 150)))).slice(0, 20);
|
||||
for (const truncated of uniqueIngredients) {
|
||||
if (truncated.length > 0) {
|
||||
await prisma.productIngredient.create({
|
||||
data: { productId: product.id, ingredient: truncated }
|
||||
});
|
||||
try {
|
||||
await prisma.productIngredient.create({
|
||||
data: { productId: product.id, ingredient: truncated }
|
||||
});
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Seed symptoms
|
||||
// Seed symptoms safely
|
||||
await prisma.productSymptom.deleteMany({ where: { productId: product.id } });
|
||||
const symptomsList = PRODUCT_SYMPTOMS_MAP[baseSlug] || [];
|
||||
const symptomsList = Array.from(new Set(PRODUCT_SYMPTOMS_MAP[baseSlug] || []));
|
||||
for (const sym of symptomsList) {
|
||||
await prisma.productSymptom.create({
|
||||
data: { productId: product.id, symptom: sym }
|
||||
});
|
||||
try {
|
||||
await prisma.productSymptom.create({
|
||||
data: { productId: product.id, symptom: sym }
|
||||
});
|
||||
} catch (_) {}
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.warn(`[Seed] Warning upserting product ${artNo}:`, err.message || err);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user