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.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m19s

This commit is contained in:
Julien Froidefond
2026-02-20 12:33:22 +01:00
parent 34b2a8c5cc
commit 9a734dc1ed

View File

@@ -428,90 +428,105 @@ async function main() {
}); });
} }
// Bootstrap demo data uniquement si la DB est vide // Upsert répondants (candidates) par nom : create si absent, update si existant. Ne vide pas les évaluations.
const evalCount = await prisma.evaluation.count(); const template = await prisma.template.findUnique({
if (evalCount === 0) { where: { id: "full-15" },
const template = await prisma.template.findUnique({ });
where: { id: "full-15" }, if (!template) throw new Error("Template not found");
});
if (!template) throw new Error("Template not found");
await prisma.user.upsert({ await prisma.user.upsert({
where: { email: "admin@cars-front.local" }, where: { email: "admin@cars-front.local" },
create: { create: {
email: "admin@cars-front.local", email: "admin@cars-front.local",
name: "Admin User", name: "Admin User",
role: "admin", 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({ const evalData = {
where: { templateId: template.id }, candidateName: r.name,
orderBy: { orderIndex: "asc" }, 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 = [ let evaluation;
{ if (existing) {
name: "Alice Chen", evaluation = await prisma.evaluation.update({
role: "Senior ML Engineer", where: { id: existing.id },
team: "Cars Front", data: evalData,
evaluator: "Jean Dupont", });
}, await prisma.dimensionScore.deleteMany({ where: { evaluationId: existing.id } });
{ } else {
name: "Bob Martin", evaluation = await prisma.evaluation.create({
role: "Data Scientist", data: evalData,
team: "Cars Front", });
evaluator: "Marie Curie", }
},
{
name: "Carol White",
role: "AI Product Manager",
team: "Cars Data",
evaluator: "Jean Dupont",
},
];
for (let i = 0; i < candidates.length; i++) { for (const d of dims) {
const c = candidates[i]; const score = 2 + Math.floor(Math.random() * 3);
const evaluation = await prisma.evaluation.create({ const { justification, examplesObserved } = getDemoResponse(d.slug, score);
await prisma.dimensionScore.create({
data: { data: {
candidateName: c.name, evaluationId: evaluation.id,
candidateRole: c.role, dimensionId: d.id,
candidateTeam: c.team, score,
evaluatorName: c.evaluator, justification,
evaluationDate: new Date(2025, 1, 15 + i), examplesObserved,
templateId: template.id, confidence: ["low", "med", "high"][Math.floor(Math.random() * 3)],
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,
}, },
}); });
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() main()