import { PrismaClient, UserRole } from '@prisma/client' import bcrypt from 'bcryptjs' const prisma = new PrismaClient() async function main() { console.log('🌱 Iniciando seed de la base de datos...') // Crear usuario administrador const hashedPassword = await bcrypt.hash('admin123', 12) const adminUser = await prisma.user.upsert({ where: { email: 'admin@universidad.edu' }, update: {}, create: { email: 'admin@universidad.edu', password: hashedPassword, role: UserRole.ADMIN, }, }) console.log('✅ Usuario administrador creado:', adminUser.email) // Crear periodo académico const period = await prisma.period.upsert({ where: { id: 'period-2024' }, update: {}, create: { id: 'period-2024', name: 'Periodo 2024', startDate: new Date('2024-01-01'), endDate: new Date('2024-12-31'), isActive: true, }, }) console.log('✅ Periodo académico creado:', period.name) // Crear parciales const partials = [ { id: 'partial-1', name: 'Primer Parcial', periodId: period.id }, { id: 'partial-2', name: 'Segundo Parcial', periodId: period.id }, { id: 'partial-3', name: 'Tercer Parcial', periodId: period.id }, ] for (const partial of partials) { await prisma.partial.upsert({ where: { id: partial.id, }, update: {}, create: partial, }) console.log(`✅ Parcial creado: ${partial.name}`) } // Crear clases de ejemplo const classes = [ { name: 'Matemáticas I', code: 'MAT101', description: 'Fundamentos de matemáticas', periodId: period.id, }, { name: 'Programación I', code: 'PRG101', description: 'Introducción a la programación', periodId: period.id, }, { name: 'Física I', code: 'FIS101', description: 'Fundamentos de física', periodId: period.id, }, ] for (const classData of classes) { const createdClass = await prisma.class.upsert({ where: { code: classData.code }, update: {}, create: classData, }) // Crear secciones para cada clase const sections = ['A', 'B'] for (const sectionName of sections) { await prisma.section.upsert({ where: { id: `${createdClass.code}-${sectionName}` }, update: {}, create: { id: `${createdClass.code}-${sectionName}`, name: sectionName, classId: createdClass.id, }, }) console.log(`✅ Sección creada: ${sectionName} para ${createdClass.name}`) } } console.log('✅ Clases y secciones creadas') // Crear profesor de ejemplo const teacherPassword = await bcrypt.hash('teacher123', 12) const teacherUser = await prisma.user.upsert({ where: { email: 'profesor@universidad.edu' }, update: {}, create: { email: 'profesor@universidad.edu', password: teacherPassword, role: UserRole.TEACHER, }, }) const teacher = await prisma.teacher.upsert({ where: { userId: teacherUser.id }, update: {}, create: { userId: teacherUser.id, firstName: 'Juan', lastName: 'Pérez', cedula: '1234567890', email: 'profesor@universidad.edu', phone: '0987654321', }, }) console.log('✅ Profesor creado:', teacher.firstName, teacher.lastName) // Crear estudiante de ejemplo const studentPassword = await bcrypt.hash('student123', 12) const studentUser = await prisma.user.upsert({ where: { email: 'estudiante@universidad.edu' }, update: {}, create: { email: 'estudiante@universidad.edu', password: studentPassword, role: UserRole.STUDENT, }, }) const student = await prisma.student.upsert({ where: { userId: studentUser.id }, update: {}, create: { userId: studentUser.id, firstName: 'María', lastName: 'González', cedula: '0987654321', email: 'estudiante@universidad.edu', phone: '0123456789', admissionNumber: 'EST2024001', }, }) console.log('✅ Estudiante creado:', student.firstName, student.lastName) console.log('🎉 Seed completado exitosamente!') console.log('\n📋 Credenciales de acceso:') console.log('Administrador: admin@universidad.edu / admin123') console.log('Profesor: profesor@universidad.edu / teacher123') console.log('Estudiante: estudiante@universidad.edu / student123') } main() .catch((e) => { console.error('❌ Error durante el seed:', e) process.exit(1) }) .finally(async () => { await prisma.$disconnect() })