기본 구조 설계 및 데이터베이스 생성

This commit is contained in:
2025-09-02 11:11:48 +09:00
parent 1bf28291b5
commit 3129e3663f
4 changed files with 1062 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
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();

View File

@@ -0,0 +1,196 @@
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
async function insertCommonCodeData() {
try {
console.log("=== 공통코드 기본 데이터 삽입 시작 ===");
// 기존 데이터 삭제 (재실행 시 중복 방지)
await prisma.$executeRaw`DELETE FROM code_info WHERE code_category IN ('USER_STATUS', 'USER_TYPE', 'DEPT_TYPE', 'LANGUAGE', 'CURRENCY')`;
await prisma.$executeRaw`DELETE FROM code_category WHERE category_code IN ('USER_STATUS', 'USER_TYPE', 'DEPT_TYPE', 'LANGUAGE', 'CURRENCY')`;
console.log("✅ 기존 데이터 정리 완료");
// 1. 카테고리 삽입
const categories = [
[
"USER_STATUS",
"사용자 상태",
"User Status",
"사용자의 활성화 상태를 나타내는 코드",
1,
],
[
"USER_TYPE",
"사용자 타입",
"User Type",
"사용자의 권한 타입을 구분하는 코드",
2,
],
[
"DEPT_TYPE",
"부서 타입",
"Department Type",
"부서의 분류를 나타내는 코드",
3,
],
[
"LANGUAGE",
"언어 코드",
"Language Code",
"시스템에서 지원하는 언어 코드",
4,
],
[
"CURRENCY",
"통화 코드",
"Currency Code",
"시스템에서 지원하는 통화 코드",
5,
],
];
for (const [code, name, nameEng, desc, order] of categories) {
await prisma.$executeRaw`
INSERT INTO code_category (category_code, category_name, category_name_eng, description, sort_order, is_active, created_date, created_by, updated_date, updated_by)
VALUES (${code}, ${name}, ${nameEng}, ${desc}, ${order}, 'Y', now(), 'SYSTEM', now(), 'SYSTEM')
`;
}
console.log("✅ 카테고리 데이터 삽입 완료");
// 2. 코드 정보 삽입
const codes = [
// 사용자 상태
["USER_STATUS", "A", "활성", "Active", "정상적으로 활동 중인 사용자", 1],
[
"USER_STATUS",
"I",
"비활성",
"Inactive",
"일시적으로 비활성화된 사용자",
2,
],
[
"USER_STATUS",
"S",
"휴면",
"Sleep",
"장기간 미접속으로 휴면 상태인 사용자",
3,
],
["USER_STATUS", "D", "삭제", "Deleted", "삭제 처리된 사용자", 4],
// 사용자 타입
[
"USER_TYPE",
"ADMIN",
"관리자",
"Administrator",
"시스템 전체를 관리할 수 있는 최고 권한",
1,
],
[
"USER_TYPE",
"USER",
"일반사용자",
"User",
"일반적인 업무 기능을 사용할 수 있는 사용자",
2,
],
[
"USER_TYPE",
"GUEST",
"게스트",
"Guest",
"제한적인 기능만 사용할 수 있는 게스트 사용자",
3,
],
[
"USER_TYPE",
"PARTNER",
"협력업체",
"Partner",
"협력업체 직원으로 특정 기능만 사용 가능",
4,
],
// 부서 타입
[
"DEPT_TYPE",
"SALES",
"영업부",
"Sales Department",
"영업 관련 업무를 담당하는 부서",
1,
],
[
"DEPT_TYPE",
"DEV",
"개발부",
"Development Department",
"시스템 개발을 담당하는 부서",
2,
],
[
"DEPT_TYPE",
"HR",
"인사부",
"Human Resources Department",
"인사 관리를 담당하는 부서",
3,
],
[
"DEPT_TYPE",
"FINANCE",
"재무부",
"Finance Department",
"재무 관리를 담당하는 부서",
4,
],
[
"DEPT_TYPE",
"ADMIN",
"관리부",
"Administration Department",
"일반 관리 업무를 담당하는 부서",
5,
],
// 언어 코드
["LANGUAGE", "KR", "한국어", "Korean", "한국어 언어 설정", 1],
["LANGUAGE", "US", "영어", "English", "영어 언어 설정", 2],
["LANGUAGE", "CN", "중국어", "Chinese", "중국어 언어 설정", 3],
["LANGUAGE", "JP", "일본어", "Japanese", "일본어 언어 설정", 4],
// 통화 코드
["CURRENCY", "KRW", "원", "Korean Won", "대한민국 원화", 1],
["CURRENCY", "USD", "달러", "US Dollar", "미국 달러", 2],
["CURRENCY", "EUR", "유로", "Euro", "유럽 유로", 3],
["CURRENCY", "JPY", "엔", "Japanese Yen", "일본 엔화", 4],
["CURRENCY", "CNY", "위안", "Chinese Yuan", "중국 위안화", 5],
];
for (const [category, value, name, nameEng, desc, order] of codes) {
await prisma.$executeRaw`
INSERT INTO code_info (code_category, code_value, code_name, code_name_eng, description, sort_order, is_active, created_date, created_by, updated_date, updated_by)
VALUES (${category}, ${value}, ${name}, ${nameEng}, ${desc}, ${order}, 'Y', now(), 'SYSTEM', now(), 'SYSTEM')
`;
}
console.log("✅ 코드 정보 데이터 삽입 완료");
// 3. 삽입 결과 확인
const categoryCount =
await prisma.$queryRaw`SELECT COUNT(*) as count FROM code_category WHERE created_by = 'SYSTEM'`;
const codeCount =
await prisma.$queryRaw`SELECT COUNT(*) as count FROM code_info WHERE created_by = 'SYSTEM'`;
console.log(`📊 삽입된 카테고리 수: ${categoryCount[0].count}`);
console.log(`📊 삽입된 코드 수: ${codeCount[0].count}`);
console.log("🎉 공통코드 기본 데이터 삽입 완료!");
} catch (error) {
console.error("❌ 오류 발생:", error);
} finally {
await prisma.$disconnect();
}
}
insertCommonCodeData();

View File

@@ -5145,3 +5145,50 @@ model screen_menu_assignments {
@@unique([screen_id, menu_objid, company_code])
@@index([company_code])
}
// =====================================================
// 공통코드 관리 시스템 모델
// =====================================================
/// 공통코드 카테고리 테이블
model code_category {
category_code String @id @db.VarChar(50)
category_name String @db.VarChar(100)
category_name_eng String? @db.VarChar(100)
description String? @db.Text
sort_order Int @default(0)
is_active String @default("Y") @db.Char(1)
created_date DateTime? @default(now()) @db.Timestamp(6)
created_by String? @db.VarChar(50)
updated_date DateTime? @default(now()) @db.Timestamp(6)
updated_by String? @db.VarChar(50)
// 관계 - 코드 상세 정보
codes code_info[]
@@index([is_active])
@@index([sort_order])
}
/// 공통코드 상세 정보 테이블
model code_info {
code_category String @db.VarChar(50)
code_value String @db.VarChar(50)
code_name String @db.VarChar(100)
code_name_eng String? @db.VarChar(100)
description String? @db.Text
sort_order Int @default(0)
is_active String @default("Y") @db.Char(1)
created_date DateTime? @default(now()) @db.Timestamp(6)
created_by String? @db.VarChar(50)
updated_date DateTime? @default(now()) @db.Timestamp(6)
updated_by String? @db.VarChar(50)
// 관계 - 코드 카테고리
category code_category @relation(fields: [code_category], references: [category_code], onDelete: Cascade, onUpdate: Cascade)
@@id([code_category, code_value])
@@index([code_category])
@@index([is_active])
@@index([code_category, sort_order])
}