fix(migration): reorder constraint expansion before backfill UPDATE
Migration 0005 gagal karena UPDATE state='in_progress' dijalankan sebelum constraint lama di-drop. Constraint lama (dari 0001) hanya mengizinkan 'not_started','completed','scored' sehingga 'in_progress' ditolak PostgreSQL (CheckViolation). Fix: pindahkan DROP/CREATE constraint ke sebelum blok UPDATE backfill.
This commit is contained in:
parent
467b146988
commit
e3eba57d71
|
|
@ -46,6 +46,17 @@ def upgrade() -> None:
|
|||
sa.Column("composite_percent", sa.Float(), nullable=True),
|
||||
)
|
||||
|
||||
# Perluas constraint state menjadi 5-state SEBELUM backfill update,
|
||||
# agar nilai 'in_progress' diizinkan saat UPDATE di bawah.
|
||||
op.drop_constraint(
|
||||
"ck_student_progress_state", "student_progress", type_="check"
|
||||
)
|
||||
op.create_check_constraint(
|
||||
"ck_student_progress_state",
|
||||
"student_progress",
|
||||
"state IN ('not_started','in_progress','completed','scored','done')",
|
||||
)
|
||||
|
||||
# Backfill: completed → exercise lulus; scored → ambil skor kuis lama.
|
||||
op.execute(
|
||||
"UPDATE student_progress SET exercise_passed = true "
|
||||
|
|
@ -63,16 +74,6 @@ def upgrade() -> None:
|
|||
"WHERE state IN ('completed', 'scored')"
|
||||
)
|
||||
|
||||
# Perluas constraint state menjadi 5-state.
|
||||
op.drop_constraint(
|
||||
"ck_student_progress_state", "student_progress", type_="check"
|
||||
)
|
||||
op.create_check_constraint(
|
||||
"ck_student_progress_state",
|
||||
"student_progress",
|
||||
"state IN ('not_started','in_progress','completed','scored','done')",
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_constraint(
|
||||
|
|
|
|||
Loading…
Reference in New Issue