fix(scripts): SQLAlchemy 트랜잭션 에러 수정
autobegin 상태에서 begin() 재호출 에러 → engine.begin() 컨텍스트 매니저로 변경. 189건 PostgreSQL weight_min_kg/weight_max_kg 업데이트 완료. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2ef418ed7c
commit
f92abf94c8
@ -524,23 +524,20 @@ def main():
|
|||||||
# ── DB 업데이트 ──
|
# ── DB 업데이트 ──
|
||||||
if not dry_run and updates:
|
if not dry_run and updates:
|
||||||
print(f'\n DB 업데이트 시작...')
|
print(f'\n DB 업데이트 시작...')
|
||||||
tx = conn.begin()
|
conn.close()
|
||||||
try:
|
with pg.begin() as tx_conn:
|
||||||
for apc_code, wmin, wmax, _, _ in updates:
|
for apc_code, wmin, wmax, _, _ in updates:
|
||||||
conn.execute(text('''
|
tx_conn.execute(text('''
|
||||||
UPDATE apc
|
UPDATE apc
|
||||||
SET weight_min_kg = :wmin, weight_max_kg = :wmax
|
SET weight_min_kg = :wmin, weight_max_kg = :wmax
|
||||||
WHERE apc = :apc
|
WHERE apc = :apc
|
||||||
'''), {'wmin': wmin, 'wmax': wmax, 'apc': apc_code})
|
'''), {'wmin': wmin, 'wmax': wmax, 'apc': apc_code})
|
||||||
tx.commit()
|
print(f' 완료: {len(updates)}건 업데이트')
|
||||||
print(f' 완료: {len(updates)}건 업데이트')
|
|
||||||
except Exception as e:
|
|
||||||
tx.rollback()
|
|
||||||
print(f' 오류 발생, 롤백: {e}')
|
|
||||||
elif not dry_run and not updates:
|
elif not dry_run and not updates:
|
||||||
print('\n 업데이트할 항목이 없습니다.')
|
print('\n 업데이트할 항목이 없습니다.')
|
||||||
|
conn.close()
|
||||||
conn.close()
|
else:
|
||||||
|
conn.close()
|
||||||
print('\n완료.')
|
print('\n완료.')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user