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
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()