From 9a734dc1ed8c92c7c1962cb8d3a8c01b9b69cfc3 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Fri, 20 Feb 2026 12:33:22 +0100 Subject: [PATCH] Refactor seed data to upsert candidates and evaluations, ensuring existing evaluations are updated without clearing previous data. Enhance the evaluation creation process with detailed scoring and justification for improved clarity and relevance. --- prisma/seed.ts | 161 +++++++++++++++++++++++++++---------------------- 1 file changed, 88 insertions(+), 73 deletions(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index 63e843d..a35ffb7 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -428,90 +428,105 @@ async function main() { }); } - // Bootstrap demo data uniquement si la DB est vide - const evalCount = await prisma.evaluation.count(); - if (evalCount === 0) { - const template = await prisma.template.findUnique({ - where: { id: "full-15" }, - }); - if (!template) throw new Error("Template not found"); + // Upsert répondants (candidates) par nom : create si absent, update si existant. Ne vide pas les évaluations. + const template = await prisma.template.findUnique({ + where: { id: "full-15" }, + }); + if (!template) throw new Error("Template not found"); - await prisma.user.upsert({ - where: { email: "admin@cars-front.local" }, - create: { - email: "admin@cars-front.local", - name: "Admin User", - role: "admin", + await prisma.user.upsert({ + where: { email: "admin@cars-front.local" }, + create: { + email: "admin@cars-front.local", + name: "Admin User", + role: "admin", + }, + update: {}, + }); + + const dims = await prisma.templateDimension.findMany({ + where: { templateId: template.id }, + orderBy: { orderIndex: "asc" }, + }); + + const repondants = [ + { + name: "Alice Chen", + role: "Senior ML Engineer", + team: "Cars Front", + evaluator: "Jean Dupont", + }, + { + name: "Bob Martin", + role: "Data Scientist", + team: "Cars Front", + evaluator: "Marie Curie", + }, + { + name: "Carol White", + role: "AI Product Manager", + team: "Cars Data", + evaluator: "Jean Dupont", + }, + ]; + + for (let i = 0; i < repondants.length; i++) { + const r = repondants[i]; + const existing = await prisma.evaluation.findFirst({ + where: { + candidateName: r.name, + evaluatorName: r.evaluator, }, - update: {}, + orderBy: { evaluationDate: "desc" }, }); - const dims = await prisma.templateDimension.findMany({ - where: { templateId: template.id }, - orderBy: { orderIndex: "asc" }, - }); + const evalData = { + candidateName: r.name, + candidateRole: r.role, + candidateTeam: r.team, + evaluatorName: r.evaluator, + evaluationDate: new Date(2025, 1, 15 + i), + templateId: template.id, + status: i === 0 ? "submitted" : "draft", + findings: + i === 0 + ? "Bonne maîtrise des outils et des prompts. Conception et exploration à renforcer. Alignement NFR correct." + : null, + recommendations: + i === 0 + ? "Encourager le mode plan avant implémentation. Veille sur les workflows IA." + : null, + }; - const candidates = [ - { - name: "Alice Chen", - role: "Senior ML Engineer", - team: "Cars Front", - evaluator: "Jean Dupont", - }, - { - name: "Bob Martin", - role: "Data Scientist", - team: "Cars Front", - evaluator: "Marie Curie", - }, - { - name: "Carol White", - role: "AI Product Manager", - team: "Cars Data", - evaluator: "Jean Dupont", - }, - ]; + let evaluation; + if (existing) { + evaluation = await prisma.evaluation.update({ + where: { id: existing.id }, + data: evalData, + }); + await prisma.dimensionScore.deleteMany({ where: { evaluationId: existing.id } }); + } else { + evaluation = await prisma.evaluation.create({ + data: evalData, + }); + } - for (let i = 0; i < candidates.length; i++) { - const c = candidates[i]; - const evaluation = await prisma.evaluation.create({ + for (const d of dims) { + const score = 2 + Math.floor(Math.random() * 3); + const { justification, examplesObserved } = getDemoResponse(d.slug, score); + await prisma.dimensionScore.create({ data: { - candidateName: c.name, - candidateRole: c.role, - candidateTeam: c.team, - evaluatorName: c.evaluator, - evaluationDate: new Date(2025, 1, 15 + i), - templateId: template.id, - status: i === 0 ? "submitted" : "draft", - findings: - i === 0 - ? "Bonne maîtrise des outils et des prompts. Conception et exploration à renforcer. Alignement NFR correct." - : null, - recommendations: - i === 0 - ? "Encourager le mode plan avant implémentation. Veille sur les workflows IA." - : null, + evaluationId: evaluation.id, + dimensionId: d.id, + score, + justification, + examplesObserved, + confidence: ["low", "med", "high"][Math.floor(Math.random() * 3)], }, }); - for (const d of dims) { - const score = 2 + Math.floor(Math.random() * 3); - const { justification, examplesObserved } = getDemoResponse(d.slug, score); - await prisma.dimensionScore.create({ - data: { - evaluationId: evaluation.id, - dimensionId: d.id, - score, - justification, - examplesObserved, - confidence: ["low", "med", "high"][Math.floor(Math.random() * 3)], - }, - }); - } } - console.log("Seed complete: templates synced, demo evaluations created"); - } else { - console.log("Seed complete: templates synced, evaluations preserved"); } + console.log("Seed complete: templates synced, répondants upserted (évaluations non vidées)"); } main()