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,9 +428,7 @@ async function main() {
});
}
// Bootstrap demo data uniquement si la DB est vide
const evalCount = await prisma.evaluation.count();
if (evalCount === 0) {
// 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" },
});
@@ -451,7 +449,7 @@ async function main() {
orderBy: { orderIndex: "asc" },
});
const candidates = [
const repondants = [
{
name: "Alice Chen",
role: "Senior ML Engineer",
@@ -472,14 +470,21 @@ async function main() {
},
];
for (let i = 0; i < candidates.length; i++) {
const c = candidates[i];
const evaluation = await prisma.evaluation.create({
data: {
candidateName: c.name,
candidateRole: c.role,
candidateTeam: c.team,
evaluatorName: c.evaluator,
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,
},
orderBy: { evaluationDate: "desc" },
});
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",
@@ -491,8 +496,21 @@ async function main() {
i === 0
? "Encourager le mode plan avant implémentation. Veille sur les workflows IA."
: null,
},
};
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 (const d of dims) {
const score = 2 + Math.floor(Math.random() * 3);
const { justification, examplesObserved } = getDemoResponse(d.slug, score);
@@ -508,10 +526,7 @@ async function main() {
});
}
}
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()