const { PrismaClient } = require("@prisma/client"); const prisma = new PrismaClient(); // 기본 템플릿 데이터 정의 const defaultTemplates = [ { template_code: "advanced-data-table-v2", template_name: "고급 데이터 테이블 v2", template_name_eng: "Advanced Data Table v2", description: "검색, 필터링, 페이징, CRUD 기능이 포함된 완전한 데이터 테이블 컴포넌트", category: "table", icon_name: "table", default_size: { width: 1000, height: 680, }, layout_config: { components: [ { type: "datatable", label: "고급 데이터 테이블", position: { x: 0, y: 0 }, size: { width: 1000, height: 680 }, style: { border: "1px solid #e5e7eb", borderRadius: "8px", backgroundColor: "#ffffff", padding: "0", }, columns: [ { id: "id", label: "ID", type: "number", visible: true, sortable: true, filterable: false, width: 80, }, { id: "name", label: "이름", type: "text", visible: true, sortable: true, filterable: true, width: 150, }, { id: "email", label: "이메일", type: "email", visible: true, sortable: true, filterable: true, width: 200, }, { id: "status", label: "상태", type: "select", visible: true, sortable: true, filterable: true, width: 100, }, { id: "created_date", label: "생성일", type: "date", visible: true, sortable: true, filterable: true, width: 120, }, ], filters: [ { id: "status", label: "상태", type: "select", options: [ { label: "전체", value: "" }, { label: "활성", value: "active" }, { label: "비활성", value: "inactive" }, ], }, { id: "name", label: "이름", type: "text" }, { id: "email", label: "이메일", type: "text" }, ], pagination: { enabled: true, pageSize: 10, pageSizeOptions: [5, 10, 20, 50, 100], showPageSizeSelector: true, showPageInfo: true, showFirstLast: true, }, actions: { showSearchButton: true, searchButtonText: "검색", enableExport: true, enableRefresh: true, enableAdd: true, enableEdit: true, enableDelete: true, addButtonText: "추가", editButtonText: "수정", deleteButtonText: "삭제", }, addModalConfig: { title: "새 데이터 추가", description: "테이블에 새로운 데이터를 추가합니다.", width: "lg", layout: "two-column", gridColumns: 2, fieldOrder: ["name", "email", "status"], requiredFields: ["name", "email"], hiddenFields: ["id", "created_date"], advancedFieldConfigs: { status: { type: "select", options: [ { label: "활성", value: "active" }, { label: "비활성", value: "inactive" }, ], }, }, submitButtonText: "추가", cancelButtonText: "취소", }, }, ], }, sort_order: 1, is_active: "Y", is_public: "Y", company_code: "*", created_by: "system", updated_by: "system", }, { template_code: "universal-button", template_name: "범용 버튼", template_name_eng: "Universal Button", description: "다양한 기능을 설정할 수 있는 범용 버튼. 상세설정에서 기능을 선택하세요.", category: "button", icon_name: "mouse-pointer", default_size: { width: 80, height: 36, }, layout_config: { components: [ { type: "widget", widgetType: "button", label: "버튼", position: { x: 0, y: 0 }, size: { width: 80, height: 36 }, style: { backgroundColor: "#3b82f6", color: "#ffffff", border: "none", borderRadius: "6px", fontSize: "14px", fontWeight: "500", }, }, ], }, sort_order: 2, is_active: "Y", is_public: "Y", company_code: "*", created_by: "system", updated_by: "system", }, { template_code: "file-upload", template_name: "파일 첨부", template_name_eng: "File Upload", description: "드래그앤드롭 파일 업로드 영역", category: "file", icon_name: "upload", default_size: { width: 300, height: 120, }, layout_config: { components: [ { type: "widget", widgetType: "file", label: "파일 첨부", position: { x: 0, y: 0 }, size: { width: 300, height: 120 }, style: { border: "2px dashed #d1d5db", borderRadius: "8px", backgroundColor: "#f9fafb", display: "flex", alignItems: "center", justifyContent: "center", fontSize: "14px", color: "#6b7280", }, }, ], }, sort_order: 3, is_active: "Y", is_public: "Y", company_code: "*", created_by: "system", updated_by: "system", }, { template_code: "form-container", template_name: "폼 컨테이너", template_name_eng: "Form Container", description: "입력 폼을 위한 기본 컨테이너 레이아웃", category: "form", icon_name: "form", default_size: { width: 400, height: 300, }, layout_config: { components: [ { type: "container", label: "폼 컨테이너", position: { x: 0, y: 0 }, size: { width: 400, height: 300 }, style: { border: "1px solid #e5e7eb", borderRadius: "8px", backgroundColor: "#ffffff", padding: "16px", }, }, ], }, sort_order: 4, is_active: "Y", is_public: "Y", company_code: "*", created_by: "system", updated_by: "system", }, ]; async function seedTemplates() { console.log("🌱 템플릿 시드 데이터 삽입 시작..."); try { // 기존 템플릿이 있는지 확인하고 없는 경우에만 삽입 for (const template of defaultTemplates) { const existing = await prisma.template_standards.findUnique({ where: { template_code: template.template_code }, }); if (!existing) { await prisma.template_standards.create({ data: template, }); console.log(`✅ 템플릿 '${template.template_name}' 생성됨`); } else { console.log(`⏭️ 템플릿 '${template.template_name}' 이미 존재함`); } } console.log("🎉 템플릿 시드 데이터 삽입 완료!"); } catch (error) { console.error("❌ 템플릿 시드 데이터 삽입 실패:", error); throw error; } finally { await prisma.$disconnect(); } } // 스크립트가 직접 실행될 때만 시드 함수 실행 if (require.main === module) { seedTemplates().catch((error) => { console.error(error); process.exit(1); }); } module.exports = { seedTemplates };