-- Drop stale FK constraints left behind when `purchases` was renamed to
-- `purchases_archived_pre_wipe` (ALTER TABLE RENAME drags FKs along).
-- Each table already carries a correct FK to order_line where required;
-- these stale ones reject every new row (23503) and block the money path.
-- IF EXISTS: constraints never existed in migration-replayed test DBs.
ALTER TABLE IF EXISTS "vendor_payout_releases" DROP CONSTRAINT IF EXISTS "vendor_payout_releases_purchase_id_fkey";--> statement-breakpoint
ALTER TABLE IF EXISTS "shipment_purchases" DROP CONSTRAINT IF EXISTS "shipment_purchases_purchase_id_fkey";--> statement-breakpoint
ALTER TABLE IF EXISTS "returns" DROP CONSTRAINT IF EXISTS "returns_purchase_id_fkey";--> statement-breakpoint
ALTER TABLE IF EXISTS "invoices" DROP CONSTRAINT IF EXISTS "invoices_purchase_id_fkey";--> statement-breakpoint
ALTER TABLE IF EXISTS "promo_redemptions" DROP CONSTRAINT IF EXISTS "promo_redemptions_purchase_id_fkey";--> statement-breakpoint
ALTER TABLE IF EXISTS "loyalty_memberships" DROP CONSTRAINT IF EXISTS "loyalty_memberships_joined_via_purchase_id_purchases_id_fk";--> statement-breakpoint
ALTER TABLE IF EXISTS "refunds" DROP CONSTRAINT IF EXISTS "refunds_purchase_id_fkey";
