import "dotenv/config"; import { PrismaClient } from "../src/generated/prisma/client.js"; import { PrismaPg } from "@prisma/adapter-pg"; const connectionString = process.env.DATABASE_URL; if (!connectionString) { throw new Error("DATABASE_URL is not set"); } const adapter = new PrismaPg({ connectionString }); const prisma = new PrismaClient({ adapter }); async function seed() { console.log("Seeding database..."); await prisma.state.createMany({ data: [ { name: "new" }, { name: "active" }, { name: "resolved" }, { name: "closed" }, ], }); const tasks = [ { title: "Complete Project Proposal", description: "Prepare and submit the project proposal for approval.", dueDate: "2023-12-15", stateHistory: [ { state: "new", date: "2023-12-01" }, { state: "active", date: "2023-12-05" }, ], notes: ["Check proposal guidelines", "Include budget estimates"], }, { title: "Design Wireframes", description: "Create wireframes for the user interface.", dueDate: "2023-12-20", stateHistory: [ { state: "new", date: "2023-12-02" }, { state: "active", date: "2023-12-06" }, ], notes: ["Review design patterns", "Seek feedback from the team"], }, { title: "Implement User Authentication", description: "Develop user authentication functionality.", dueDate: "2023-12-25", stateHistory: [ { state: "new", date: "2023-12-03" }, { state: "active", date: "2023-12-07" }, ], notes: ["Research secure authentication methods", "Implement password hashing"], }, { title: "Write API Documentation", description: "Document the RESTful API for external developers.", dueDate: "2023-12-30", stateHistory: [ { state: "new", date: "2023-12-04" }, { state: "active", date: "2023-12-08" }, ], notes: ["Use Swagger/OpenAPI for documentation", "Provide clear examples"], }, { title: "Bug Fixes and Testing", description: "Address reported bugs and perform thorough testing.", dueDate: "2024-01-05", stateHistory: [ { state: "new", date: "2023-12-05" }, { state: "active", date: "2023-12-09" }, ], notes: ["Create test cases for critical scenarios", "Perform regression testing"], }, { title: "Project Deployment", description: "Prepare for and deploy the project to production.", dueDate: "2024-01-10", stateHistory: [ { state: "new", date: "2023-12-06" }, { state: "active", date: "2023-12-10" }, ], notes: ["Coordinate with DevOps for deployment", "Monitor performance after deployment"], }, ]; for (const task of tasks) { await prisma.task.create({ data: { title: task.title, description: task.description, dueDate: task.dueDate, stateHistory: { create: task.stateHistory.map((entry, index) => ({ state: entry.state, date: entry.date, order: index, })), }, notes: { create: task.notes.map((content, index) => ({ content, order: index, })), }, }, }); } console.log("Seed completed!"); } seed() .catch((e) => { console.error(e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });