diff --git a/backend/scripts/fill_weight_from_dosage.py b/backend/scripts/fill_weight_from_dosage.py index 495d896..fe86261 100644 --- a/backend/scripts/fill_weight_from_dosage.py +++ b/backend/scripts/fill_weight_from_dosage.py @@ -524,23 +524,20 @@ def main(): # ── DB 업데이트 ── if not dry_run and updates: print(f'\n DB 업데이트 시작...') - tx = conn.begin() - try: + conn.close() + with pg.begin() as tx_conn: for apc_code, wmin, wmax, _, _ in updates: - conn.execute(text(''' + tx_conn.execute(text(''' UPDATE apc SET weight_min_kg = :wmin, weight_max_kg = :wmax WHERE apc = :apc '''), {'wmin': wmin, 'wmax': wmax, 'apc': apc_code}) - tx.commit() - print(f' 완료: {len(updates)}건 업데이트') - except Exception as e: - tx.rollback() - print(f' 오류 발생, 롤백: {e}') + print(f' 완료: {len(updates)}건 업데이트') elif not dry_run and not updates: print('\n 업데이트할 항목이 없습니다.') - - conn.close() + conn.close() + else: + conn.close() print('\n완료.')