import { PrismaClient } from "@prisma/client"; import bcrypt from "bcryptjs"; const prisma = new PrismaClient(); async function main() { console.log("🌱 μ‹œλ“œ 데이터 생성을 μ‹œμž‘ν•©λ‹ˆλ‹€..."); // κΈ°λ³Έ ν…Œλ„ŒνŠΈ 생성 const defaultTenant = await prisma.tenant.upsert({ where: { domain: "default.local" }, update: {}, create: { name: "κΈ°λ³Έ 쑰직", slug: "default", domain: "default.local", description: "κΈ°λ³Έ μ‘°μ§μž…λ‹ˆλ‹€", settings: JSON.stringify({ allowUserRegistration: true, maxUsers: 100, features: ["cms", "analytics", "seo"], }), status: "ACTIVE", isActive: true, }, }); console.log("βœ… κΈ°λ³Έ ν…Œλ„ŒνŠΈ 생성 μ™„λ£Œ:", defaultTenant.name); // κ΄€λ¦¬μž μ‚¬μš©μž 생성 const adminPassword = await bcrypt.hash("admin123!", 12); const adminUser = await prisma.user.upsert({ where: { email: "admin@example.com" }, update: {}, create: { email: "admin@example.com", name: "μ‹œμŠ€ν…œ κ΄€λ¦¬μž", password: adminPassword, role: "ADMIN", isActive: true, emailVerified: new Date(), tenantId: defaultTenant.id, failedLogins: 0, }, }); console.log("βœ… κ΄€λ¦¬μž μ‚¬μš©μž 생성 μ™„λ£Œ:", adminUser.email); // ν…œν”Œλ¦Ώ 데이터 생성 (Business Template) const businessTemplate = await prisma.siteTemplate.upsert({ where: { slug: "business-template" }, update: {}, create: { name: "Business Template", slug: "business-template", description: "전문적인 λΉ„μ¦ˆλ‹ˆμŠ€ μ›Ήμ‚¬μ΄νŠΈλ₯Ό μœ„ν•œ ν…œν”Œλ¦Ώ", category: "BUSINESS", pricing: "FREE", sections: JSON.stringify({ hero: { type: "hero", props: ["title", "subtitle", "cta"] }, features: { type: "features", props: ["items", "columns"] }, about: { type: "about", props: ["content", "image"] }, contact: { type: "contact", props: ["form", "info"] }, }), styles: JSON.stringify({ colors: { primary: "#1a365d", secondary: "#2d3748", }, layout: "standard", }), previewImage: "/templates/business-preview.jpg", previewUrl: "https://business-demo.example.com", features: "responsive,seo-optimized,contact-form", tags: "business,professional,corporate", isActive: true, isPublic: true, }, }); console.log("βœ… Business ν…œν”Œλ¦Ώ 생성 μ™„λ£Œ:", businessTemplate.name); // Portfolio Template const portfolioTemplate = await prisma.siteTemplate.upsert({ where: { slug: "portfolio-template" }, update: {}, create: { name: "Portfolio Template", slug: "portfolio-template", description: "개인 ν¬νŠΈν΄λ¦¬μ˜€μ™€ ν¬λ¦¬μ—μ΄ν‹°λΈŒ μž‘μ—…μ„ μœ„ν•œ ν…œν”Œλ¦Ώ", category: "PORTFOLIO", pricing: "FREE", sections: JSON.stringify({ hero: { type: "hero", props: ["name", "title", "image"] }, portfolio: { type: "portfolio", props: ["projects", "filter"] }, about: { type: "about", props: ["bio", "skills"] }, contact: { type: "contact", props: ["form", "social"] }, }), styles: JSON.stringify({ colors: { primary: "#7c3aed", secondary: "#a855f7", }, layout: "creative", }), previewImage: "/templates/portfolio-preview.jpg", previewUrl: "https://portfolio-demo.example.com", features: "gallery,animations,responsive", tags: "portfolio,creative,personal", isActive: true, isPublic: true, }, }); console.log("βœ… Portfolio ν…œν”Œλ¦Ώ 생성 μ™„λ£Œ:", portfolioTemplate.name); // ν…ŒμŠ€νŠΈ μ‚¬μ΄νŠΈ 생성 const testSite = await prisma.site.upsert({ where: { slug: "my-first-site" }, update: {}, create: { name: "λ‚˜μ˜ 첫 번째 μ‚¬μ΄νŠΈ", slug: "my-first-site", subdomain: "my-first-site", description: "ν…ŒμŠ€νŠΈμš© μ‚¬μ΄νŠΈμž…λ‹ˆλ‹€", templateId: businessTemplate.id, status: "DRAFT", isPublished: false, ownerId: adminUser.id, settings: JSON.stringify({ theme: { primaryColor: "#1a365d", secondaryColor: "#2d3748", }, seo: { title: "λ‚˜μ˜ 첫 번째 μ‚¬μ΄νŠΈ", description: "ν…ŒμŠ€νŠΈμš© μ‚¬μ΄νŠΈμž…λ‹ˆλ‹€", }, }), }, }); console.log("βœ… ν…ŒμŠ€νŠΈ μ‚¬μ΄νŠΈ 생성 μ™„λ£Œ:", testSite.name); console.log("πŸŽ‰ μ‹œλ“œ 데이터 생성이 μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€!"); } main() .catch((e) => { console.error("❌ μ‹œλ“œ 데이터 생성 쀑 였λ₯˜:", e); process.exit(1); }) .finally(async () => { await prisma.$disconnect(); });