import "dotenv/config"; import { PrismaPg } from "@prisma/adapter-pg"; import { PrismaClient } from "../src/generated/prisma/client"; import { addDays } from "date-fns"; const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL! }); const prisma = new PrismaClient({ adapter }); async function main() { console.log("Seeding stage dates for calendar view (Catalog Images specifically)..."); // Get only Catalog Images stages const stages = await prisma.deliverableStage.findMany({ where: { template: { name: "Catalog Images" } }, take: 50, }); if (stages.length === 0) { console.log("No Catalog Images stages found to update."); return; } const today = new Date(); for (let i = 0; i < stages.length; i++) { const stage = stages[i]; // Spread start dates from 14 days ago to 14 days in the future const startOffset = Math.floor(Math.random() * 28) - 14; const startDate = addDays(today, startOffset); // Duration approx 8 weeks (56 days), plus some random variance const durationDays = 56 + Math.floor(Math.random() * 10) - 5; const dueDate = addDays(startDate, durationDays); await prisma.deliverableStage.update({ where: { id: stage.id }, data: { startDate, dueDate, } }); console.log(`Updated Catalog Images stage ${stage.id}: Start: ${startDate.toISOString().split('T')[0]}, Due: ${dueDate.toISOString().split('T')[0]}`); } console.log(`Successfully updated ${stages.length} Catalog Images stages with dates.`); } main() .catch((e) => { console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });