import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient({ log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'], }); async function seed() { console.log('Seeding database...'); const count = await prisma.project.count(); if (count > 0) { console.log('Database already seeded.'); return; } const projects = await prisma.project.createManyAndReturn({ data: [ { name: 'Personal', description: 'Personal tasks and goals', color: '#3b82f6', sortOrder: 1 }, { name: 'Work', description: 'Work-related tasks', color: '#10b981', sortOrder: 2 }, { name: 'Health', description: 'Health and fitness', color: '#f59e0b', sortOrder: 3 }, { name: 'Finance', description: 'Financial tasks and tracking', color: '#8b5cf6', sortOrder: 4 }, ], }) as Array<{ id: string; name: string }>; // Map project names to IDs const projectMap = new Map(projects.map(p => [p.name, p.id])); const today = new Date(); const tasks: Array<{ projectId: string; title: string; description: string; priority: 'low' | 'medium' | 'high' | 'urgent'; status: 'todo' | 'in_progress' | 'done'; dueDate: Date; sortOrder: number; }> = [ { projectId: projectMap.get('Personal')!, title: 'Set up daily routine', description: 'Morning meditation, exercise, and planning', priority: 'high', status: 'todo', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1), sortOrder: 1 }, { projectId: projectMap.get('Personal')!, title: 'Read 30 minutes', description: 'Read a book or articles', priority: 'medium', status: 'todo', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 2), sortOrder: 2 }, { projectId: projectMap.get('Personal')!, title: 'Clean apartment', description: 'Deep clean kitchen and bathrooms', priority: 'medium', status: 'in_progress', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 3), sortOrder: 3 }, { projectId: projectMap.get('Work')!, title: 'Review sprint backlog', description: 'Prioritize tasks for next sprint', priority: 'high', status: 'todo', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1), sortOrder: 1 }, { projectId: projectMap.get('Work')!, title: 'Update documentation', description: 'Add API docs for new endpoints', priority: 'medium', status: 'in_progress', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 5), sortOrder: 2 }, { projectId: projectMap.get('Work')!, title: 'Code review', description: 'Review pull requests from team', priority: 'low', status: 'done', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1), sortOrder: 3 }, { projectId: projectMap.get('Health')!, title: 'Gym workout', description: 'Upper body strength training', priority: 'high', status: 'todo', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1), sortOrder: 1 }, { projectId: projectMap.get('Health')!, title: 'Meal prep', description: 'Prepare healthy meals for the week', priority: 'medium', status: 'todo', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 2), sortOrder: 2 }, { projectId: projectMap.get('Health')!, title: 'Track water intake', description: 'Drink at least 8 glasses of water', priority: 'low', status: 'done', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1), sortOrder: 3 }, { projectId: projectMap.get('Finance')!, title: 'Review monthly budget', description: 'Check spending and adjust categories', priority: 'high', status: 'todo', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 3), sortOrder: 1 }, { projectId: projectMap.get('Finance')!, title: 'Pay bills', description: 'Electricity, internet, phone', priority: 'urgent', status: 'todo', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1), sortOrder: 2 }, { projectId: projectMap.get('Finance')!, title: 'Investment review', description: 'Check portfolio performance', priority: 'medium', status: 'todo', dueDate: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7), sortOrder: 3 }, ]; await prisma.task.createMany({ data: tasks }); console.log('Seed data inserted successfully!'); } seed() .catch((e) => { console.error('Seed failed:', e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });