Skip to content

Commit

Permalink
19361 - Fix foreigin key issue on routing slip status change (#1801)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jxio authored Oct 29, 2024
1 parent df67e08 commit 0336a01
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,42 @@ def upgrade():
with op.batch_alter_table('routing_slips', schema=None) as batch_op:
batch_op.add_column(sa.Column('refund_status', sa.String(length=50), nullable=True))

# 1. Insert the new status into the `routing_slip_status_codes` table
op.execute(f"""
UPDATE routing_slip_status_codes
SET code = '{RoutingSlipStatus.REFUND_PROCESSED.value}', description = 'Refund Processed'
WHERE code = 'REFUND_COMPLETED';
INSERT INTO routing_slip_status_codes (code, description)
VALUES ('{RoutingSlipStatus.REFUND_PROCESSED.value}', 'Refund Processed')
ON CONFLICT (code) DO NOTHING;
""")

# Update the records in routing_slips where status is 'REFUND_COMPLETED'
# 2. Update the status reference in the `routing_slips` table
op.execute(f"""
UPDATE routing_slips
SET status = '{RoutingSlipStatus.REFUND_PROCESSED.value}'
WHERE status = 'REFUND_COMPLETED';
""")

# 3. Delete the old status `REFUND_COMPLETED`
op.execute("""
DELETE FROM routing_slip_status_codes
WHERE code = 'REFUND_COMPLETED';
""")


def downgrade():
op.execute("""
INSERT INTO routing_slip_status_codes (code, description)
VALUES ('REFUND_COMPLETED', 'Refund Complete')
ON CONFLICT (code) DO NOTHING;
""")

op.execute(f"""
UPDATE routing_slips
SET status = 'REFUND_COMPLETED'
WHERE status = '{RoutingSlipStatus.REFUND_PROCESSED.value}';
""")

op.execute(f"""
UPDATE routing_slip_status_codes
SET code = 'REFUND_COMPLETED', description = 'Refund Complete'
DELETE FROM routing_slip_status_codes
WHERE code = '{RoutingSlipStatus.REFUND_PROCESSED.value}';
""")

Expand Down

0 comments on commit 0336a01

Please sign in to comment.