const { PrismaClient } = require("@prisma/client"); const prisma = new PrismaClient(); async function createCommonCodeTables() { try { console.log("=== 공통코드 테이블 생성 시작 ==="); // 1. code_category 테이블 생성 await prisma.$executeRaw` CREATE TABLE IF NOT EXISTS code_category ( category_code VARCHAR(50) PRIMARY KEY, category_name VARCHAR(100) NOT NULL, category_name_eng VARCHAR(100), description TEXT, sort_order INTEGER DEFAULT 0, is_active CHAR(1) DEFAULT 'Y', created_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_by VARCHAR(50), updated_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_by VARCHAR(50) ) `; console.log("✅ code_category 테이블 생성 완료"); // 2. code_info 테이블 생성 await prisma.$executeRaw` CREATE TABLE IF NOT EXISTS code_info ( code_category VARCHAR(50) NOT NULL, code_value VARCHAR(50) NOT NULL, code_name VARCHAR(100) NOT NULL, code_name_eng VARCHAR(100), description TEXT, sort_order INTEGER DEFAULT 0, is_active CHAR(1) DEFAULT 'Y', created_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_by VARCHAR(50), updated_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_by VARCHAR(50), PRIMARY KEY (code_category, code_value), CONSTRAINT fk_code_info_category FOREIGN KEY (code_category) REFERENCES code_category(category_code) ON DELETE CASCADE ON UPDATE CASCADE ) `; console.log("✅ code_info 테이블 생성 완료"); // 3. 인덱스 생성 await prisma.$executeRaw` CREATE INDEX IF NOT EXISTS idx_code_category_active ON code_category(is_active) `; await prisma.$executeRaw` CREATE INDEX IF NOT EXISTS idx_code_category_sort ON code_category(sort_order) `; await prisma.$executeRaw` CREATE INDEX IF NOT EXISTS idx_code_info_category ON code_info(code_category) `; await prisma.$executeRaw` CREATE INDEX IF NOT EXISTS idx_code_info_active ON code_info(is_active) `; await prisma.$executeRaw` CREATE INDEX IF NOT EXISTS idx_code_info_sort ON code_info(code_category, sort_order) `; console.log("✅ 인덱스 생성 완료"); console.log("🎉 공통코드 테이블 생성 완료!"); } catch (error) { console.error("❌ 오류 발생:", error); } finally { await prisma.$disconnect(); } } createCommonCodeTables();