diff options
| author | joonhoekim <26rote@gmail.com> | 2025-07-31 12:29:52 +0000 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-07-31 12:29:52 +0000 |
| commit | 494b8925db9aa442941b936ca1b9cfaefdb75f00 (patch) | |
| tree | 96fa045bea197577dc680fb62905edb8046a992d | |
| parent | 0728ce2e0c085b8f1e8699bcdbe3d2000208bc74 (diff) | |
(김준회) MDG 수신 로직 개선건 오류 수정, 마이그레이션 대응 및 유틸 스크립트 경로 이동, DB connection 개수 제한
| -rw-r--r-- | app/api/(S-ERP)/(MDG)/IF_MDZ_EVCP_MATERIAL_MASTER_PART/route.ts | 4 | ||||
| -rw-r--r-- | db/db.ts | 3 | ||||
| -rw-r--r-- | lib/soap/batch-utils.ts | 11 | ||||
| -rw-r--r-- | lib/soap/mdg/send/vendor-master/action.ts | 2 |
4 files changed, 11 insertions, 9 deletions
diff --git a/app/api/(S-ERP)/(MDG)/IF_MDZ_EVCP_MATERIAL_MASTER_PART/route.ts b/app/api/(S-ERP)/(MDG)/IF_MDZ_EVCP_MATERIAL_MASTER_PART/route.ts index 49aff036..97c5f1c1 100644 --- a/app/api/(S-ERP)/(MDG)/IF_MDZ_EVCP_MATERIAL_MASTER_PART/route.ts +++ b/app/api/(S-ERP)/(MDG)/IF_MDZ_EVCP_MATERIAL_MASTER_PART/route.ts @@ -24,10 +24,6 @@ import { bulkUpsert, bulkReplaceSubTableData } from "@/lib/soap/batch-utils"; -import { - bulkUpsert, - bulkReplaceSubTableData -} from "@/lib/soap/batch-utils"; // 스키마에서 직접 타입 추론 (Insert와 XML을 통합) type MatlData = typeof MATERIAL_MASTER_PART_MATL.$inferInsert; @@ -4,7 +4,8 @@ import * as schema from './schema'; const pool = new Pool({ // connectionString: process.env.DATABASE_URL as string, - connectionString: "postgresql://dts:dujinDTS2@localhost:5432/evcp" + connectionString: "postgresql://dts:dujinDTS2@localhost:5432/evcp", + max: Number(process.env.DB_POOL_MAX) || 4, }); const db = drizzle(pool, { schema }); diff --git a/lib/soap/batch-utils.ts b/lib/soap/batch-utils.ts index 785c85eb..76127fc2 100644 --- a/lib/soap/batch-utils.ts +++ b/lib/soap/batch-utils.ts @@ -71,10 +71,15 @@ export async function bulkReplaceSubTableData<T extends Record<string, unknown>> parentIds: string[], chunkSize: number = 1000, ) { + // FK 값이 없는 서브테이블 건은 생략 if (!parentIds.length) return; - - // 1. 기존 데이터 일괄 삭제 - await tx.delete(table).where(inArray(parentField, parentIds)); + + // 마이그레이션시는 삭제 생략 + const skipDelete = process.env.SOAP_IGNORE_DELETE_FOR_MIGRATION === "true"; + + if (!skipDelete) { + await tx.delete(table).where(inArray(parentField, parentIds)); + } // 2. 새 데이터 일괄 삽입 (chunking) if (!data.length) return; diff --git a/lib/soap/mdg/send/vendor-master/action.ts b/lib/soap/mdg/send/vendor-master/action.ts index 88b46508..d35d7a76 100644 --- a/lib/soap/mdg/send/vendor-master/action.ts +++ b/lib/soap/mdg/send/vendor-master/action.ts @@ -17,7 +17,7 @@ import { VENDOR_MASTER_BP_HEADER_BP_VENGEN_BP_PORG_ZVPFN } from "@/db/schema/MDG/mdg"; import { eq, sql, desc } from "drizzle-orm"; -import { withSoapLogging } from "../../utils"; +import { withSoapLogging } from "../../../utils"; import { XMLBuilder } from 'fast-xml-parser'; import { CSV_FIELDS } from './csv-fields'; |
