From c8f24d60f3f449dc3acbd3db4bf1f19796c60bb2 Mon Sep 17 00:00:00 2001 From: SeongHyun Kim Date: Mon, 6 Apr 2026 12:20:09 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20batch=5Fid=20=EC=BB=AC=EB=9F=BC=20?= =?UTF-8?q?=EC=97=86=EC=9D=84=20=EB=95=8C=20fallback=20+=20=ED=8A=B8?= =?UTF-8?q?=EB=9E=9C=EC=9E=AD=EC=85=98=20=EC=95=88=EC=A0=84=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - batch_id 컬럼 존재 여부를 사전 확인 후 INSERT 쿼리 분기 - 트랜잭션 내 try-catch fallback 대신 조건부 컬럼 방식으로 변경 - 배포 DB에 ALTER TABLE 권한 없어도 정상 동작 --- .../controllers/popProductionController.ts | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/backend-node/src/controllers/popProductionController.ts b/backend-node/src/controllers/popProductionController.ts index 7a9e6394..7dac3ad2 100644 --- a/backend-node/src/controllers/popProductionController.ts +++ b/backend-node/src/controllers/popProductionController.ts @@ -1757,31 +1757,32 @@ export const acceptProcess = async (req: AuthenticatedRequest, res: Response) => }); } - // batch_id 생성 또는 전달받은 값 사용 - // 프론트에서 batch_id를 전달하면 이어받고, 없으면 새로 생성 + // batch_id: 컬럼이 있으면 포함, 없으면 제외 const batchId = req.body.batch_id || `BATCH-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`; + const hasBatchCol = _batchMigrationDone; - // 분할 행 INSERT (원본 행에서 공정 정보 복사 + batch_id) - await ensureBatchIdColumn(); - const result = await client.query( - `INSERT INTO work_order_process ( - id, wo_id, seq_no, process_code, process_name, is_required, is_fixed_order, + // 분할 행 INSERT (batch_id는 컬럼 존재 시에만) + const insertCols = `id, wo_id, seq_no, process_code, process_name, is_required, is_fixed_order, standard_time, equipment_code, routing_detail_id, status, input_qty, good_qty, defect_qty, total_production_qty, result_status, accepted_by, accepted_at, started_at, - parent_process_id, company_code, writer, batch_id - ) VALUES ( - gen_random_uuid()::text, $1, $2, $3, $4, $5, $6, $7, $8, $9, + parent_process_id, company_code, writer${hasBatchCol ? ", batch_id" : ""}`; + const insertVals = `gen_random_uuid()::text, $1, $2, $3, $4, $5, $6, $7, $8, $9, 'in_progress', $10, '0', '0', '0', 'draft', $11, NOW()::text, NOW()::text, - $12, $13, $11, $14 - ) RETURNING id, input_qty, status, process_name, result_status, accepted_by, batch_id`, - [ - row.wo_id, row.seq_no, row.process_code, row.process_name, - row.is_required, row.is_fixed_order, row.standard_time, - row.equipment_code, row.routing_detail_id, - String(qty), userId, masterId, companyCode, batchId, - ] + $12, $13, $11${hasBatchCol ? ", $14" : ""}`; + const insertParams = [ + row.wo_id, row.seq_no, row.process_code, row.process_name, + row.is_required, row.is_fixed_order, row.standard_time, + row.equipment_code, row.routing_detail_id, + String(qty), userId, masterId, companyCode, + ...(hasBatchCol ? [batchId] : []), + ]; + + const result = await client.query( + `INSERT INTO work_order_process (${insertCols}) VALUES (${insertVals}) + RETURNING id, input_qty, status, process_name, result_status, accepted_by`, + insertParams ); // 분할 행에 체크리스트 복사