DO $$
BEGIN
    IF EXISTS (
        SELECT 1
        FROM pg_constraint
        WHERE conname = 'fk_purchase_items_purchase'
            AND conrelid = 'purchase_items'::regclass
    ) THEN
        ALTER TABLE purchase_items
            DROP CONSTRAINT fk_purchase_items_purchase;
    END IF;
END $$;

DROP TABLE IF EXISTS purchases;
