feat: Phase 3.13 EntityJoinService Raw Query 전환 완료
엔티티 조인 관계 관리 서비스의 모든 Prisma 호출을 Raw Query로 전환 전환 완료: 5개 Prisma 호출 1. detectEntityJoins - 엔티티 컬럼 감지 - column_labels.findMany to query - web_type = entity 필터 2-3. validateJoinConfig - 테이블/컬럼 존재 확인 - queryRaw to query - information_schema 조회 4-5. getReferenceTableColumns - 컬럼 정보/라벨 조회 - queryRaw, findMany to query - 문자열 타입 컬럼 필터링 기술적 개선사항: - information_schema 쿼리 파라미터 바인딩 - IS NOT NULL 조건 변환 - 타입 안전성 강화 문서: PHASE3.13_ENTITY_JOIN_SERVICE_MIGRATION.md 진행률: Phase 3 141/162 (87.0%)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import prisma from "../config/database";
|
||||
import { query, queryOne } from "../database/db";
|
||||
import { logger } from "../utils/logger";
|
||||
import {
|
||||
EntityJoinConfig,
|
||||
@@ -26,20 +25,20 @@ export class EntityJoinService {
|
||||
logger.info(`Entity 컬럼 감지 시작: ${tableName}`);
|
||||
|
||||
// column_labels에서 entity 타입인 컬럼들 조회
|
||||
const entityColumns = await prisma.column_labels.findMany({
|
||||
where: {
|
||||
table_name: tableName,
|
||||
web_type: "entity",
|
||||
reference_table: { not: null },
|
||||
reference_column: { not: null },
|
||||
},
|
||||
select: {
|
||||
column_name: true,
|
||||
reference_table: true,
|
||||
reference_column: true,
|
||||
display_column: true,
|
||||
},
|
||||
});
|
||||
const entityColumns = await query<{
|
||||
column_name: string;
|
||||
reference_table: string;
|
||||
reference_column: string;
|
||||
display_column: string | null;
|
||||
}>(
|
||||
`SELECT column_name, reference_table, reference_column, display_column
|
||||
FROM column_labels
|
||||
WHERE table_name = $1
|
||||
AND web_type = $2
|
||||
AND reference_table IS NOT NULL
|
||||
AND reference_column IS NOT NULL`,
|
||||
[tableName, "entity"]
|
||||
);
|
||||
|
||||
logger.info(`🔍 Entity 컬럼 조회 결과: ${entityColumns.length}개 발견`);
|
||||
entityColumns.forEach((col, index) => {
|
||||
@@ -401,13 +400,14 @@ export class EntityJoinService {
|
||||
});
|
||||
|
||||
// 참조 테이블 존재 확인
|
||||
const tableExists = await prisma.$queryRaw`
|
||||
SELECT 1 FROM information_schema.tables
|
||||
WHERE table_name = ${config.referenceTable}
|
||||
LIMIT 1
|
||||
`;
|
||||
const tableExists = await query<{ exists: number }>(
|
||||
`SELECT 1 as exists FROM information_schema.tables
|
||||
WHERE table_name = $1
|
||||
LIMIT 1`,
|
||||
[config.referenceTable]
|
||||
);
|
||||
|
||||
if (!Array.isArray(tableExists) || tableExists.length === 0) {
|
||||
if (tableExists.length === 0) {
|
||||
logger.warn(`참조 테이블이 존재하지 않음: ${config.referenceTable}`);
|
||||
return false;
|
||||
}
|
||||
@@ -420,14 +420,15 @@ export class EntityJoinService {
|
||||
|
||||
// 🚨 display_column이 항상 "none"이므로, 표시 컬럼이 없어도 조인 허용
|
||||
if (displayColumn && displayColumn !== "none") {
|
||||
const columnExists = await prisma.$queryRaw`
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = ${config.referenceTable}
|
||||
AND column_name = ${displayColumn}
|
||||
LIMIT 1
|
||||
`;
|
||||
const columnExists = await query<{ exists: number }>(
|
||||
`SELECT 1 as exists FROM information_schema.columns
|
||||
WHERE table_name = $1
|
||||
AND column_name = $2
|
||||
LIMIT 1`,
|
||||
[config.referenceTable, displayColumn]
|
||||
);
|
||||
|
||||
if (!Array.isArray(columnExists) || columnExists.length === 0) {
|
||||
if (columnExists.length === 0) {
|
||||
logger.warn(
|
||||
`표시 컬럼이 존재하지 않음: ${config.referenceTable}.${displayColumn}`
|
||||
);
|
||||
@@ -528,27 +529,30 @@ export class EntityJoinService {
|
||||
> {
|
||||
try {
|
||||
// 1. 테이블의 기본 컬럼 정보 조회
|
||||
const columns = (await prisma.$queryRaw`
|
||||
SELECT
|
||||
const columns = await query<{
|
||||
column_name: string;
|
||||
data_type: string;
|
||||
}>(
|
||||
`SELECT
|
||||
column_name,
|
||||
data_type
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = ${tableName}
|
||||
WHERE table_name = $1
|
||||
AND data_type IN ('character varying', 'varchar', 'text', 'char')
|
||||
ORDER BY ordinal_position
|
||||
`) as Array<{
|
||||
column_name: string;
|
||||
data_type: string;
|
||||
}>;
|
||||
ORDER BY ordinal_position`,
|
||||
[tableName]
|
||||
);
|
||||
|
||||
// 2. column_labels 테이블에서 라벨 정보 조회
|
||||
const columnLabels = await prisma.column_labels.findMany({
|
||||
where: { table_name: tableName },
|
||||
select: {
|
||||
column_name: true,
|
||||
column_label: true,
|
||||
},
|
||||
});
|
||||
const columnLabels = await query<{
|
||||
column_name: string;
|
||||
column_label: string | null;
|
||||
}>(
|
||||
`SELECT column_name, column_label
|
||||
FROM column_labels
|
||||
WHERE table_name = $1`,
|
||||
[tableName]
|
||||
);
|
||||
|
||||
// 3. 라벨 정보를 맵으로 변환
|
||||
const labelMap = new Map<string, string>();
|
||||
|
||||
Reference in New Issue
Block a user