ERP-node/frontend/types/ddl.ts

347 lines
7.4 KiB
TypeScript
Raw Normal View History

/**
* DDL ()
*/
// 기본 웹타입
export type WebType =
| "text"
| "number"
| "decimal"
| "date"
| "datetime"
| "boolean"
| "code"
| "entity"
| "textarea"
| "select"
| "checkbox"
| "radio"
| "file"
| "email"
| "tel";
// 컬럼 정의 인터페이스
export interface CreateColumnDefinition {
/** 컬럼명 (영문자, 숫자, 언더스코어만 허용) */
name: string;
/** 컬럼 라벨 (화면 표시용) */
label?: string;
2025-09-23 10:40:21 +09:00
/** 입력타입 */
inputType: string;
/** 웹타입 (레거시 호환용) */
webType?: WebType;
/** NULL 허용 여부 */
nullable?: boolean;
/** 컬럼 길이 (text, code 타입에서 사용) */
length?: number;
/** 기본값 */
defaultValue?: string;
/** 컬럼 설명 */
description?: string;
/** 표시 순서 */
order?: number;
/** 상세 설정 (JSON 형태) */
detailSettings?: Record<string, any>;
}
// 테이블 생성 요청 인터페이스
export interface CreateTableRequest {
/** 테이블명 */
tableName: string;
/** 테이블 설명 */
description?: string;
/** 컬럼 정의 목록 */
columns: CreateColumnDefinition[];
}
// 컬럼 추가 요청 인터페이스
export interface AddColumnRequest {
/** 컬럼 정의 */
column: CreateColumnDefinition;
}
// DDL 실행 결과 인터페이스
export interface DDLExecutionResult {
/** 실행 성공 여부 */
success: boolean;
/** 결과 메시지 */
message: string;
/** 결과 데이터 */
data?: any;
/** 오류 정보 */
error?: {
code: string;
details: string;
};
}
// 검증 결과 인터페이스
export interface ValidationResult {
/** 검증 통과 여부 */
isValid: boolean;
/** 오류 메시지 목록 */
errors: string[];
/** 경고 메시지 목록 */
warnings?: string[];
/** 검증 요약 */
summary?: string;
}
// DDL 실행 로그 인터페이스
export interface DDLExecutionLog {
/** 로그 ID */
id: number;
/** 사용자 ID */
user_id: string;
/** 회사 코드 */
company_code: string;
/** DDL 유형 */
ddl_type: "CREATE_TABLE" | "ADD_COLUMN" | "DROP_TABLE" | "DROP_COLUMN";
/** 테이블명 */
table_name: string;
/** 실행된 DDL 쿼리 (미리보기용) */
ddl_query_preview?: string;
/** 실행 성공 여부 */
success: boolean;
/** 오류 메시지 (실패 시) */
error_message?: string;
/** 실행 시간 */
executed_at: string;
}
// DDL 통계 인터페이스
export interface DDLStatistics {
/** 전체 실행 횟수 */
totalExecutions: number;
/** 성공 횟수 */
successfulExecutions: number;
/** 실패 횟수 */
failedExecutions: number;
/** DDL 타입별 통계 */
byDDLType: Record<string, number>;
/** 사용자별 통계 */
byUser: Record<string, number>;
/** 최근 실패 로그 */
recentFailures: any[];
}
// 웹타입 옵션 (UI용)
export interface WebTypeOption {
value: WebType;
label: string;
description?: string;
supportsLength: boolean;
defaultLength?: number;
}
// 웹타입 옵션 목록
export const WEB_TYPE_OPTIONS: WebTypeOption[] = [
{
value: "text",
label: "텍스트",
description: "일반 텍스트 입력",
supportsLength: true,
defaultLength: 255,
},
{
value: "number",
label: "숫자",
description: "정수 입력",
supportsLength: false,
},
{
value: "decimal",
label: "소수",
description: "소수점 숫자 입력",
supportsLength: false,
},
{
value: "date",
label: "날짜",
description: "날짜 선택",
supportsLength: false,
},
{
value: "datetime",
label: "날짜시간",
description: "날짜와 시간 선택",
supportsLength: false,
},
{
value: "boolean",
label: "불린",
description: "참/거짓 값",
supportsLength: false,
},
{
value: "code",
label: "코드",
description: "공통코드 선택",
supportsLength: true,
defaultLength: 100,
},
{
value: "entity",
label: "엔티티",
description: "다른 테이블 참조",
supportsLength: false,
},
{
value: "textarea",
label: "긴 텍스트",
description: "여러 줄 텍스트 입력",
supportsLength: false,
},
{
value: "select",
label: "선택박스",
description: "드롭다운 선택",
supportsLength: true,
defaultLength: 100,
},
{
value: "checkbox",
label: "체크박스",
description: "체크박스 입력",
supportsLength: false,
},
{
value: "radio",
label: "라디오버튼",
description: "단일 선택 라디오버튼",
supportsLength: true,
defaultLength: 100,
},
{
value: "file",
label: "파일",
description: "파일 업로드",
supportsLength: false,
},
{
value: "email",
label: "이메일",
description: "이메일 주소 입력",
supportsLength: true,
defaultLength: 255,
},
{
value: "tel",
label: "전화번호",
description: "전화번호 입력",
supportsLength: true,
defaultLength: 50,
},
];
// 컬럼 정의 테이블 속성
export interface ColumnDefinitionTableProps {
columns: CreateColumnDefinition[];
onChange: (columns: CreateColumnDefinition[]) => void;
disabled?: boolean;
}
// 테이블 생성 모달 속성
export interface CreateTableModalProps {
isOpen: boolean;
onClose: () => void;
onSuccess: (result: DDLExecutionResult) => void;
feat: 테이블 복제 기능 구현 (최고 관리자 전용) ✨ 새로운 기능 - 테이블 타입 관리에 테이블 복제 기능 추가 - 기존 테이블의 설정과 컬럼 정보를 복사하여 새 테이블 생성 - 최고 관리자만 사용 가능 (company_code = '*' AND userType = 'SUPER_ADMIN') - 테이블 1개 선택 시에만 복제 버튼 활성화 🎨 UI 개선 - 테이블 목록에 '테이블 복제' 버튼 추가 (Copy 아이콘) - CreateTableModal을 복제 모드로 재사용 - 복제 모드 시 제목/설명/버튼 텍스트 동적 변경 - 원본 테이블 정보 자동 로드 🔧 기술적 개선 - CreateTableModal에 mode/sourceTableName props 추가 - 복제 모드 감지 및 데이터 자동 로드 로직 구현 - API 타입 정의 수정 (ColumnListData 인터페이스 추가) - 백엔드 응답 구조와 프론트엔드 타입 일치화 🐛 버그 수정 - API 응답 구조 불일치 문제 해결 - ColumnListResponse 타입 수정 (배열 → 객체) - 데이터 파싱 로직 수정 (data.columns 접근) - 디버그 로그 추가로 문제 추적 개선 📝 변경된 파일 - frontend/app/(main)/admin/tableMng/page.tsx - frontend/components/admin/CreateTableModal.tsx - frontend/lib/api/tableManagement.ts - frontend/types/ddl.ts - 테이블_복제_기능_구현_계획서.md (신규) ✅ 테스트 완료 - 최고 관리자 권한 체크 - 테이블 정보 로드 - 컬럼 정보 복제 - 새 테이블명 입력 및 검증 - 테이블 생성 및 목록 갱신
2025-10-31 17:58:49 +09:00
// 🆕 복제 모드 관련
mode?: "create" | "duplicate";
sourceTableName?: string; // 복제 대상 테이블명
}
// 컬럼 추가 모달 속성
export interface AddColumnModalProps {
isOpen: boolean;
onClose: () => void;
tableName: string;
onSuccess: (result: DDLExecutionResult) => void;
}
// DDL 로그 뷰어 속성
export interface DDLLogViewerProps {
isOpen: boolean;
onClose: () => void;
}
// 유효성 검사 규칙
export const VALIDATION_RULES = {
tableName: {
pattern: /^[a-zA-Z_][a-zA-Z0-9_]*$/,
minLength: 2,
maxLength: 63,
errorMessage: "테이블명은 영문자로 시작하고, 영문자/숫자/언더스코어만 사용 가능합니다 (2-63자)",
},
columnName: {
pattern: /^[a-zA-Z_][a-zA-Z0-9_]*$/,
minLength: 2,
maxLength: 63,
errorMessage: "컬럼명은 영문자로 시작하고, 영문자/숫자/언더스코어만 사용 가능합니다 (2-63자)",
},
columnLength: {
min: 1,
max: 65535,
errorMessage: "컬럼 길이는 1 이상 65535 이하여야 합니다",
},
} as const;
// 시스템 테이블 목록 (보호 대상)
export const SYSTEM_TABLES = [
"user_info",
"company_mng",
"menu_info",
"auth_group",
"table_labels",
"column_labels",
"screen_definitions",
"screen_layouts",
"common_code",
"multi_lang_key_master",
"multi_lang_text",
"button_action_standards",
"ddl_execution_log",
] as const;
// 예약어 목록
export const RESERVED_WORDS = [
"user",
"order",
"group",
"table",
"column",
"index",
"select",
"insert",
"update",
"delete",
"from",
"where",
"join",
"on",
"as",
"and",
"or",
"not",
"null",
"true",
"false",
"create",
"alter",
"drop",
"primary",
"key",
"foreign",
"references",
"constraint",
"default",
"unique",
"check",
"view",
"procedure",
"function",
] as const;
// 예약된 컬럼명 목록 (자동 추가되는 기본 컬럼들)
export const RESERVED_COLUMNS = ["id", "created_date", "updated_date", "company_code"] as const;