2025-10-27 11:11:08 +09:00
|
|
|
|
import { PostgreSQLService } from "./PostgreSQLService";
|
|
|
|
|
|
import fs from "fs";
|
|
|
|
|
|
import path from "path";
|
2025-10-16 14:59:07 +09:00
|
|
|
|
|
2026-03-03 21:53:46 +09:00
|
|
|
|
/**
|
|
|
|
|
|
* 결재 시스템 테이블 마이그레이션
|
|
|
|
|
|
* approval_definitions, approval_line_templates, approval_line_template_steps,
|
|
|
|
|
|
* approval_requests, approval_lines 테이블 생성
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function runApprovalSystemMigration() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
console.log("🔄 결재 시스템 마이그레이션 시작...");
|
|
|
|
|
|
|
|
|
|
|
|
const sqlFilePath = path.join(
|
|
|
|
|
|
__dirname,
|
|
|
|
|
|
"../../db/migrations/100_create_approval_system.sql"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(sqlFilePath)) {
|
|
|
|
|
|
console.log("⚠️ 마이그레이션 파일이 없습니다:", sqlFilePath);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const sqlContent = fs.readFileSync(sqlFilePath, "utf8");
|
|
|
|
|
|
await PostgreSQLService.query(sqlContent);
|
|
|
|
|
|
|
|
|
|
|
|
console.log("✅ 결재 시스템 마이그레이션 완료!");
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("❌ 결재 시스템 마이그레이션 실패:", error);
|
|
|
|
|
|
if (error instanceof Error && error.message.includes("already exists")) {
|
|
|
|
|
|
console.log("ℹ️ 테이블이 이미 존재합니다.");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-16 14:59:07 +09:00
|
|
|
|
/**
|
|
|
|
|
|
* 데이터베이스 마이그레이션 실행
|
|
|
|
|
|
* dashboard_elements 테이블에 custom_title, show_header 컬럼 추가
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function runDashboardMigration() {
|
|
|
|
|
|
try {
|
2025-10-27 11:11:08 +09:00
|
|
|
|
console.log("🔄 대시보드 마이그레이션 시작...");
|
2025-10-16 14:59:07 +09:00
|
|
|
|
|
|
|
|
|
|
// custom_title 컬럼 추가
|
|
|
|
|
|
await PostgreSQLService.query(`
|
|
|
|
|
|
ALTER TABLE dashboard_elements
|
|
|
|
|
|
ADD COLUMN IF NOT EXISTS custom_title VARCHAR(255)
|
|
|
|
|
|
`);
|
2025-10-27 11:11:08 +09:00
|
|
|
|
console.log("✅ custom_title 컬럼 추가 완료");
|
2025-10-16 14:59:07 +09:00
|
|
|
|
|
|
|
|
|
|
// show_header 컬럼 추가
|
|
|
|
|
|
await PostgreSQLService.query(`
|
|
|
|
|
|
ALTER TABLE dashboard_elements
|
|
|
|
|
|
ADD COLUMN IF NOT EXISTS show_header BOOLEAN DEFAULT true
|
|
|
|
|
|
`);
|
2025-10-27 11:11:08 +09:00
|
|
|
|
console.log("✅ show_header 컬럼 추가 완료");
|
2025-10-16 14:59:07 +09:00
|
|
|
|
|
|
|
|
|
|
// 기존 데이터 업데이트
|
|
|
|
|
|
await PostgreSQLService.query(`
|
|
|
|
|
|
UPDATE dashboard_elements
|
|
|
|
|
|
SET show_header = true
|
|
|
|
|
|
WHERE show_header IS NULL
|
|
|
|
|
|
`);
|
2025-10-27 11:11:08 +09:00
|
|
|
|
console.log("✅ 기존 데이터 업데이트 완료");
|
2025-10-16 14:59:07 +09:00
|
|
|
|
|
2025-10-27 11:11:08 +09:00
|
|
|
|
console.log("✅ 대시보드 마이그레이션 완료!");
|
2025-10-16 14:59:07 +09:00
|
|
|
|
} catch (error) {
|
2025-10-27 11:11:08 +09:00
|
|
|
|
console.error("❌ 대시보드 마이그레이션 실패:", error);
|
2025-10-16 14:59:07 +09:00
|
|
|
|
// 이미 컬럼이 있는 경우는 무시
|
2025-10-27 11:11:08 +09:00
|
|
|
|
if (error instanceof Error && error.message.includes("already exists")) {
|
|
|
|
|
|
console.log("ℹ️ 컬럼이 이미 존재합니다.");
|
2025-10-16 14:59:07 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-27 11:11:08 +09:00
|
|
|
|
/**
|
|
|
|
|
|
* 테이블 이력 보기 버튼 액션 마이그레이션
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function runTableHistoryActionMigration() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
console.log("🔄 테이블 이력 보기 액션 마이그레이션 시작...");
|
|
|
|
|
|
|
|
|
|
|
|
// SQL 파일 읽기
|
|
|
|
|
|
const sqlFilePath = path.join(
|
|
|
|
|
|
__dirname,
|
|
|
|
|
|
"../../db/migrations/024_add_table_history_view_action.sql"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(sqlFilePath)) {
|
|
|
|
|
|
console.log("⚠️ 마이그레이션 파일이 없습니다:", sqlFilePath);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const sqlContent = fs.readFileSync(sqlFilePath, "utf8");
|
|
|
|
|
|
|
|
|
|
|
|
// SQL 실행
|
|
|
|
|
|
await PostgreSQLService.query(sqlContent);
|
|
|
|
|
|
|
|
|
|
|
|
console.log("✅ 테이블 이력 보기 액션 마이그레이션 완료!");
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("❌ 테이블 이력 보기 액션 마이그레이션 실패:", error);
|
|
|
|
|
|
// 이미 액션이 있는 경우는 무시
|
|
|
|
|
|
if (
|
|
|
|
|
|
error instanceof Error &&
|
|
|
|
|
|
error.message.includes("duplicate key value")
|
|
|
|
|
|
) {
|
|
|
|
|
|
console.log("ℹ️ 액션이 이미 존재합니다.");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* DTG Management 테이블 이력 시스템 마이그레이션
|
|
|
|
|
|
*/
|
2026-03-30 17:17:20 +09:00
|
|
|
|
export async function runUserMailAccountsMigration() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
console.log("🔄 사용자 메일 계정 테이블 마이그레이션 시작...");
|
|
|
|
|
|
await PostgreSQLService.query(`
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS user_mail_accounts (
|
|
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
|
|
user_id VARCHAR(100) NOT NULL,
|
|
|
|
|
|
display_name VARCHAR(200) NOT NULL,
|
|
|
|
|
|
email VARCHAR(255) NOT NULL,
|
|
|
|
|
|
protocol VARCHAR(10) NOT NULL CHECK (protocol IN ('imap', 'pop3')),
|
|
|
|
|
|
host VARCHAR(255) NOT NULL,
|
|
|
|
|
|
port INTEGER NOT NULL,
|
|
|
|
|
|
use_tls BOOLEAN NOT NULL DEFAULT true,
|
|
|
|
|
|
username VARCHAR(255) NOT NULL,
|
|
|
|
|
|
password TEXT NOT NULL,
|
|
|
|
|
|
status VARCHAR(20) NOT NULL DEFAULT 'active',
|
|
|
|
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
|
|
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
|
|
|
|
)
|
|
|
|
|
|
`);
|
|
|
|
|
|
await PostgreSQLService.query(`
|
|
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_user_mail_accounts_user_id ON user_mail_accounts(user_id)
|
|
|
|
|
|
`);
|
|
|
|
|
|
console.log("✅ 사용자 메일 계정 테이블 마이그레이션 완료!");
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("❌ 사용자 메일 계정 테이블 마이그레이션 실패:", error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-30 18:05:54 +09:00
|
|
|
|
/**
|
|
|
|
|
|
* Messenger tables migration
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function runMessengerMigration() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
console.log("🔄 메신저 테이블 마이그레이션 시작...");
|
|
|
|
|
|
|
|
|
|
|
|
const sqlFilePath = path.join(
|
|
|
|
|
|
__dirname,
|
|
|
|
|
|
"../../../db/migrations/messenger_tables.sql"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(sqlFilePath)) {
|
|
|
|
|
|
console.log("⚠️ 마이그레이션 파일이 없습니다:", sqlFilePath);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const sqlContent = fs.readFileSync(sqlFilePath, "utf8");
|
|
|
|
|
|
await PostgreSQLService.query(sqlContent);
|
|
|
|
|
|
|
|
|
|
|
|
console.log("✅ 메신저 테이블 마이그레이션 완료!");
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("❌ 메신저 테이블 마이그레이션 실패:", error);
|
|
|
|
|
|
if (error instanceof Error && error.message.includes("already exists")) {
|
|
|
|
|
|
console.log("ℹ️ 테이블이 이미 존재합니다.");
|
2026-04-07 10:35:16 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 스마트공장 활용 로그 테이블 마이그레이션
|
|
|
|
|
|
*/
|
2026-04-07 14:16:26 +09:00
|
|
|
|
/**
|
|
|
|
|
|
* 스마트공장 스케줄 + 공휴일 테이블 마이그레이션
|
|
|
|
|
|
*/
|
|
|
|
|
|
export async function runSmartFactoryScheduleMigration() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
console.log("🔄 스마트공장 스케줄 테이블 마이그레이션 시작...");
|
|
|
|
|
|
|
|
|
|
|
|
const sqlFilePath = path.join(
|
|
|
|
|
|
__dirname,
|
|
|
|
|
|
"../../db/migrations/201_create_smart_factory_schedule.sql"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(sqlFilePath)) {
|
|
|
|
|
|
console.log("⚠️ 마이그레이션 파일이 없습니다:", sqlFilePath);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const sqlContent = fs.readFileSync(sqlFilePath, "utf8");
|
|
|
|
|
|
await PostgreSQLService.query(sqlContent);
|
|
|
|
|
|
|
|
|
|
|
|
console.log("✅ 스마트공장 스케줄 테이블 마이그레이션 완료!");
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("❌ 스마트공장 스케줄 테이블 마이그레이션 실패:", error);
|
|
|
|
|
|
if (error instanceof Error && error.message.includes("already exists")) {
|
|
|
|
|
|
console.log("ℹ️ 테이블이 이미 존재합니다.");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-07 10:35:16 +09:00
|
|
|
|
export async function runSmartFactoryLogMigration() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
console.log("🔄 스마트공장 로그 테이블 마이그레이션 시작...");
|
|
|
|
|
|
|
|
|
|
|
|
const sqlFilePath = path.join(
|
|
|
|
|
|
__dirname,
|
|
|
|
|
|
"../../db/migrations/200_create_smart_factory_log.sql"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(sqlFilePath)) {
|
|
|
|
|
|
console.log("⚠️ 마이그레이션 파일이 없습니다:", sqlFilePath);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const sqlContent = fs.readFileSync(sqlFilePath, "utf8");
|
|
|
|
|
|
await PostgreSQLService.query(sqlContent);
|
|
|
|
|
|
|
|
|
|
|
|
console.log("✅ 스마트공장 로그 테이블 마이그레이션 완료!");
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("❌ 스마트공장 로그 테이블 마이그레이션 실패:", error);
|
|
|
|
|
|
if (error instanceof Error && error.message.includes("already exists")) {
|
|
|
|
|
|
console.log("ℹ️ 테이블이 이미 존재합니다.");
|
2026-03-30 18:05:54 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-27 11:11:08 +09:00
|
|
|
|
export async function runDtgManagementLogMigration() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
console.log("🔄 DTG Management 이력 테이블 마이그레이션 시작...");
|
|
|
|
|
|
|
|
|
|
|
|
// SQL 파일 읽기
|
|
|
|
|
|
const sqlFilePath = path.join(
|
|
|
|
|
|
__dirname,
|
|
|
|
|
|
"../../db/migrations/025_create_dtg_management_log.sql"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(sqlFilePath)) {
|
|
|
|
|
|
console.log("⚠️ 마이그레이션 파일이 없습니다:", sqlFilePath);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const sqlContent = fs.readFileSync(sqlFilePath, "utf8");
|
|
|
|
|
|
|
|
|
|
|
|
// SQL 실행
|
|
|
|
|
|
await PostgreSQLService.query(sqlContent);
|
|
|
|
|
|
|
|
|
|
|
|
console.log("✅ DTG Management 이력 테이블 마이그레이션 완료!");
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("❌ DTG Management 이력 테이블 마이그레이션 실패:", error);
|
|
|
|
|
|
// 이미 테이블이 있는 경우는 무시
|
|
|
|
|
|
if (error instanceof Error && error.message.includes("already exists")) {
|
|
|
|
|
|
console.log("ℹ️ 이력 테이블이 이미 존재합니다.");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|