import { LicenseCode, PrismaClient, UserRole } from '@prisma/client' import { config } from '../src/config' import { hashPassword } from '../src/security/password' const prisma = new PrismaClient() async function main(): Promise { const professionalLicense = await prisma.license.upsert({ where: { code: LicenseCode.PRO }, create: { code: LicenseCode.PRO, name: 'Professional', description: '전문가용 라이선스', defaultDurationDays: 365 }, update: { name: 'Professional', description: '전문가용 라이선스', defaultDurationDays: 365, isActive: true } }) await prisma.license.upsert({ where: { code: LicenseCode.FREE }, create: { code: LicenseCode.FREE, name: 'Free', description: '기본 무료 라이선스', defaultDurationDays: 365 }, update: { name: 'Free', description: '기본 무료 라이선스', defaultDurationDays: 365, isActive: true } }) await prisma.license.upsert({ where: { code: LicenseCode.EDU }, create: { code: LicenseCode.EDU, name: 'Education', description: '교육기관용 라이선스', defaultDurationDays: 365 }, update: { name: 'Education', description: '교육기관용 라이선스', defaultDurationDays: 365, isActive: true } }) const admin = await prisma.user.upsert({ where: { email: config.seedAdminEmail.toLowerCase() }, create: { email: config.seedAdminEmail.toLowerCase(), name: 'ATNMY Studio Admin', role: UserRole.ADMIN, passwordHash: await hashPassword(config.seedAdminPassword) }, update: { name: 'ATNMY Studio Admin', role: UserRole.ADMIN, isActive: true } }) const existingAdminLicense = await prisma.userLicense.findFirst({ where: { userId: admin.id, expiresAt: null } }) if (!existingAdminLicense) { await prisma.userLicense.create({ data: { userId: admin.id, licenseId: professionalLicense.id } }) } await prisma.user.updateMany({ where: { email: { in: ['teacher@futuredrive.net', 'teacher@yu.ac.kr'] } }, data: { role: UserRole.USER } }) const instructors = await prisma.user.findMany({ where: { email: { in: ['teacher@futuredrive.net', 'teacher@yu.ac.kr'] } }, select: { id: true } }) for (const instructor of instructors) { await prisma.userAppRole.upsert({ where: { userId_appKey_roleCode: { userId: instructor.id, appKey: 'LMS', roleCode: 'INSTRUCTOR' } }, create: { userId: instructor.id, appKey: 'LMS', roleCode: 'INSTRUCTOR' }, update: { endsAt: null } }) } console.log(`Seeded admin user: ${config.seedAdminEmail}`) } main() .catch((error) => { console.error(error) process.exitCode = 1 }) .finally(async () => { await prisma.$disconnect() })