feat: Phase 3.15 배치 서비스 Raw Query 전환 완료
4개 서비스 24개 Prisma 호출 전환 완료 배치 서비스 전환: - BatchExternalDbService (8개) - BatchExecutionLogService (7개) - BatchManagementService (5개) - BatchSchedulerService (4개) 주요 기술: - json_agg + json_build_object - 동적 WHERE 절 - 동적 UPDATE 쿼리 - PostgreSQL placeholders Phase 3 완료 문서: PHASE3.15_BATCH_SERVICES_MIGRATION.md
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// 배치관리 전용 서비스 (기존 소스와 완전 분리)
|
||||
// 작성일: 2024-12-24
|
||||
|
||||
import prisma from "../config/database";
|
||||
import { query, queryOne } from "../database/db";
|
||||
import { PasswordEncryption } from "../utils/passwordEncryption";
|
||||
import { DatabaseConnectorFactory } from "../database/DatabaseConnectorFactory";
|
||||
|
||||
@@ -49,16 +49,18 @@ export class BatchManagementService {
|
||||
});
|
||||
|
||||
// 활성화된 외부 DB 연결 조회
|
||||
const externalConnections = await prisma.external_db_connections.findMany({
|
||||
where: { is_active: 'Y' },
|
||||
select: {
|
||||
id: true,
|
||||
connection_name: true,
|
||||
db_type: true,
|
||||
description: true
|
||||
},
|
||||
orderBy: { connection_name: 'asc' }
|
||||
});
|
||||
const externalConnections = await query<{
|
||||
id: number;
|
||||
connection_name: string;
|
||||
db_type: string;
|
||||
description: string;
|
||||
}>(
|
||||
`SELECT id, connection_name, db_type, description
|
||||
FROM external_db_connections
|
||||
WHERE is_active = 'Y'
|
||||
ORDER BY connection_name ASC`,
|
||||
[]
|
||||
);
|
||||
|
||||
// 외부 DB 연결 추가
|
||||
externalConnections.forEach(conn => {
|
||||
@@ -97,13 +99,14 @@ export class BatchManagementService {
|
||||
|
||||
if (connectionType === 'internal') {
|
||||
// 내부 DB 테이블 조회
|
||||
const result = await prisma.$queryRaw<Array<{ table_name: string }>>`
|
||||
SELECT table_name
|
||||
const result = await query<{ table_name: string }>(
|
||||
`SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'public'
|
||||
AND table_type = 'BASE TABLE'
|
||||
ORDER BY table_name
|
||||
`;
|
||||
ORDER BY table_name`,
|
||||
[]
|
||||
);
|
||||
|
||||
tables = result.map(row => ({
|
||||
table_name: row.table_name,
|
||||
@@ -153,22 +156,23 @@ export class BatchManagementService {
|
||||
// 내부 DB 컬럼 조회
|
||||
console.log(`[BatchManagementService] 내부 DB 컬럼 조회 시작: ${tableName}`);
|
||||
|
||||
const result = await prisma.$queryRaw<Array<{
|
||||
const result = await query<{
|
||||
column_name: string;
|
||||
data_type: string;
|
||||
is_nullable: string;
|
||||
column_default: string | null
|
||||
}>>`
|
||||
SELECT
|
||||
}>(
|
||||
`SELECT
|
||||
column_name,
|
||||
data_type,
|
||||
is_nullable,
|
||||
column_default
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = ${tableName}
|
||||
ORDER BY ordinal_position
|
||||
`;
|
||||
AND table_name = $1
|
||||
ORDER BY ordinal_position`,
|
||||
[tableName]
|
||||
);
|
||||
|
||||
console.log(`[BatchManagementService] 쿼리 결과:`, result);
|
||||
|
||||
@@ -215,9 +219,10 @@ export class BatchManagementService {
|
||||
private static async getExternalTables(connectionId: number): Promise<BatchApiResponse<BatchTableInfo[]>> {
|
||||
try {
|
||||
// 연결 정보 조회
|
||||
const connection = await prisma.external_db_connections.findUnique({
|
||||
where: { id: connectionId }
|
||||
});
|
||||
const connection = await queryOne<any>(
|
||||
`SELECT * FROM external_db_connections WHERE id = $1`,
|
||||
[connectionId]
|
||||
);
|
||||
|
||||
if (!connection) {
|
||||
return {
|
||||
@@ -274,9 +279,10 @@ export class BatchManagementService {
|
||||
console.log(`[BatchManagementService] getExternalTableColumns 호출: connectionId=${connectionId}, tableName=${tableName}`);
|
||||
|
||||
// 연결 정보 조회
|
||||
const connection = await prisma.external_db_connections.findUnique({
|
||||
where: { id: connectionId }
|
||||
});
|
||||
const connection = await queryOne<any>(
|
||||
`SELECT * FROM external_db_connections WHERE id = $1`,
|
||||
[connectionId]
|
||||
);
|
||||
|
||||
if (!connection) {
|
||||
console.log(`[BatchManagementService] 연결 정보를 찾을 수 없음: connectionId=${connectionId}`);
|
||||
|
||||
Reference in New Issue
Block a user