Merge branch 'dev' of http://39.117.244.52:3000/kjs/ERP-node into feature/screen-management
This commit is contained in:
@@ -279,7 +279,7 @@ export class ExternalDbConnectionService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 외부 DB 연결 삭제 (논리 삭제)
|
||||
* 외부 DB 연결 삭제 (물리 삭제)
|
||||
*/
|
||||
static async deleteConnection(id: number): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
@@ -295,13 +295,9 @@ export class ExternalDbConnectionService {
|
||||
};
|
||||
}
|
||||
|
||||
// 논리 삭제 (is_active를 'N'으로 변경)
|
||||
await prisma.external_db_connections.update({
|
||||
// 물리 삭제 (실제 데이터 삭제)
|
||||
await prisma.external_db_connections.delete({
|
||||
where: { id },
|
||||
data: {
|
||||
is_active: "N",
|
||||
updated_date: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -318,6 +314,185 @@ export class ExternalDbConnectionService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 데이터베이스 연결 테스트
|
||||
*/
|
||||
static async testConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
switch (testData.db_type.toLowerCase()) {
|
||||
case "postgresql":
|
||||
return await this.testPostgreSQLConnection(testData, startTime);
|
||||
case "mysql":
|
||||
return await this.testMySQLConnection(testData, startTime);
|
||||
case "oracle":
|
||||
return await this.testOracleConnection(testData, startTime);
|
||||
case "mssql":
|
||||
return await this.testMSSQLConnection(testData, startTime);
|
||||
case "sqlite":
|
||||
return await this.testSQLiteConnection(testData, startTime);
|
||||
default:
|
||||
return {
|
||||
success: false,
|
||||
message: `지원하지 않는 데이터베이스 타입입니다: ${testData.db_type}`,
|
||||
error: {
|
||||
code: "UNSUPPORTED_DB_TYPE",
|
||||
details: `${testData.db_type} 타입은 현재 지원하지 않습니다.`,
|
||||
},
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "연결 테스트 중 오류가 발생했습니다.",
|
||||
error: {
|
||||
code: "TEST_ERROR",
|
||||
details: error instanceof Error ? error.message : "알 수 없는 오류",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PostgreSQL 연결 테스트
|
||||
*/
|
||||
private static async testPostgreSQLConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
const { Client } = await import("pg");
|
||||
const client = new Client({
|
||||
host: testData.host,
|
||||
port: testData.port,
|
||||
database: testData.database_name,
|
||||
user: testData.username,
|
||||
password: testData.password,
|
||||
connectionTimeoutMillis: (testData.connection_timeout || 30) * 1000,
|
||||
ssl: testData.ssl_enabled === "Y" ? { rejectUnauthorized: false } : false,
|
||||
});
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
const result = await client.query(
|
||||
"SELECT version(), pg_database_size(current_database()) as size"
|
||||
);
|
||||
const responseTime = Date.now() - startTime;
|
||||
|
||||
await client.end();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "PostgreSQL 연결이 성공했습니다.",
|
||||
details: {
|
||||
response_time: responseTime,
|
||||
server_version: result.rows[0]?.version || "알 수 없음",
|
||||
database_size: this.formatBytes(
|
||||
parseInt(result.rows[0]?.size || "0")
|
||||
),
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
try {
|
||||
await client.end();
|
||||
} catch (endError) {
|
||||
// 연결 종료 오류는 무시
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: "PostgreSQL 연결에 실패했습니다.",
|
||||
error: {
|
||||
code: "CONNECTION_FAILED",
|
||||
details: error instanceof Error ? error.message : "알 수 없는 오류",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testMySQLConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
// MySQL 라이브러리가 없으므로 모의 구현
|
||||
return {
|
||||
success: false,
|
||||
message: "MySQL 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details: "MySQL 라이브러리가 설치되지 않았습니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Oracle 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testOracleConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
return {
|
||||
success: false,
|
||||
message: "Oracle 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details: "Oracle 라이브러리가 설치되지 않았습니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL Server 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testMSSQLConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
return {
|
||||
success: false,
|
||||
message: "SQL Server 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details: "SQL Server 라이브러리가 설치되지 않았습니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* SQLite 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testSQLiteConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
return {
|
||||
success: false,
|
||||
message: "SQLite 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details:
|
||||
"SQLite는 파일 기반이므로 네트워크 연결 테스트가 불가능합니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 바이트 크기를 읽기 쉬운 형태로 변환
|
||||
*/
|
||||
private static formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return "0 Bytes";
|
||||
const k = 1024;
|
||||
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* 연결 데이터 검증
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user