diff --git a/hindsight-api/alembic/versions/d9f6a3b4c5e2_rename_bank_to_interactions.py b/hindsight-api/alembic/versions/d9f6a3b4c5e2_rename_bank_to_interactions.py index 79e0422e..82d2835c 100644 --- a/hindsight-api/alembic/versions/d9f6a3b4c5e2_rename_bank_to_interactions.py +++ b/hindsight-api/alembic/versions/d9f6a3b4c5e2_rename_bank_to_interactions.py @@ -17,12 +17,12 @@ depends_on = None def upgrade(): + # Drop old check constraint FIRST (before updating data) + op.drop_constraint('memory_units_fact_type_check', 'memory_units', type_='check') + # Update existing 'bank' values to 'interactions' op.execute("UPDATE memory_units SET fact_type = 'interactions' WHERE fact_type = 'bank'") - # Drop old check constraint - op.drop_constraint('memory_units_fact_type_check', 'memory_units', type_='check') - # Create new check constraint with 'interactions' instead of 'bank' op.create_check_constraint( 'memory_units_fact_type_check', @@ -32,12 +32,12 @@ def upgrade(): def downgrade(): + # Drop new check constraint FIRST + op.drop_constraint('memory_units_fact_type_check', 'memory_units', type_='check') + # Update 'interactions' back to 'bank' op.execute("UPDATE memory_units SET fact_type = 'bank' WHERE fact_type = 'interactions'") - # Drop new check constraint - op.drop_constraint('memory_units_fact_type_check', 'memory_units', type_='check') - # Recreate old check constraint op.create_check_constraint( 'memory_units_fact_type_check',