import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); function timeAt(hour:number, minute:number) { // stocker une heure (Postgres TIME) via Date (UTC 1970-01-01) return new Date(Date.UTC(1970, 0, 1, hour, minute, 0)); } function daysAgo(n:number) { const d = new Date(); d.setUTCDate(d.getUTCDate() - n); d.setUTCHours(0,0,0,0); return d; } async function main() { const bankCodes = await prisma.bankCodes.findMany({ where: { type: 'SHIFT' }, select: { id: true } }); if (!bankCodes.length) throw new Error('Need SHIFT bank codes'); const employees = await prisma.employees.findMany({ select: { id: true } }); for (const e of employees) { const tss = await prisma.timesheets.findMany({ where: { employee_id: e.id }, select: { id: true }, }); if (!tss.length) continue; // 10 shifts / employee for (let i = 0; i < 10; i++) { const ts = tss[i % tss.length]; const bc = bankCodes[i % bankCodes.length]; const date = daysAgo(7 + i); // la dernière quinzaine const startH = 8 + (i % 3); // 8..10 const endH = startH + 7 + (i % 2); // 15..17 await prisma.shifts.create({ data: { timesheet_id: ts.id, bank_code_id: bc.id, description: `Shift ${i + 1} for emp ${e.id}`, date, start_time: timeAt(startH, 0), end_time: timeAt(endH, 0), is_approved: Math.random() < 0.5, }, }); } } const total = await prisma.shifts.count(); console.log(`✓ Shifts: ${total} total rows`); } main().finally(() => prisma.$disconnect());