Skip to content

Commit 02ffaff

Browse files
committed
fix: payment 데이터 마이그레이션 파일들에 대해 명시적 transaction 선언
1 parent 660af08 commit 02ffaff

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

app/shop/order/migrations/0002_migrate_from_legacy.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from enum import StrEnum
3232

33-
from django.db import connections, migrations
33+
from django.db import connections, migrations, transaction
3434

3535
EMAIL_REWRITE_OLD = "@pycon.kr"
3636
EMAIL_REWRITE_NEW = "@python.or.kr"
@@ -276,7 +276,12 @@ def migrate_data(apps, schema_editor):
276276
if "legacy" not in connections.databases:
277277
return # 개발/테스트 환경 또는 cutover 완료 후 — no-op.
278278

279-
with connections["legacy"].cursor() as legacy_cur, connections["default"].cursor() as target_cur:
279+
# 중간 실패 시 target DB 의 모든 변경을 함께 롤백 (legacy DB 는 SELECT 만 — 롤백 불필요).
280+
with (
281+
transaction.atomic(using="default"),
282+
connections["legacy"].cursor() as legacy_cur,
283+
connections["default"].cursor() as target_cur,
284+
):
280285
user_id_map = _build_user_id_map(target_cur, legacy_cur)
281286
_copy_shifted_users(target_cur, legacy_cur, user_id_map)
282287
_update_matched_unique_id(target_cur, legacy_cur, user_id_map)
@@ -292,6 +297,7 @@ def migrate_data(apps, schema_editor):
292297

293298

294299
class Migration(migrations.Migration):
300+
atomic = True
295301
dependencies = [
296302
("user", "0009_alter_historicaluserext_options_and_more"),
297303
("order", "0001_initial"),

app/shop/product/migrations/0002_image_to_publicfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def _noop_reverse(apps, schema_editor) -> None:
4646

4747

4848
class Migration(migrations.Migration):
49+
atomic = True # 다단계 operation 중간 실패 시 컬럼 추가/제거 + 데이터 이관 일괄 롤백.
4950
dependencies = [("file", "0001_initial"), ("product", "0001_initial")]
5051
operations = [
5152
# 1) 신규 FK 컬럼 추가

0 commit comments

Comments
 (0)