-- Trial / grant credits: a server-owned, idempotent balance grant that is not -- a payment. Extends the existing kind constraint; safe to re-run. DO $$ DECLARE cname text; BEGIN SELECT conname INTO cname FROM pg_constraint WHERE conrelid = 'opt_credit_events'::regclass AND contype = 'c' AND pg_get_constraintdef(oid) LIKE '%kind%'; IF cname IS NOT NULL THEN EXECUTE format('ALTER TABLE opt_credit_events DROP CONSTRAINT %I', cname); END IF; ALTER TABLE opt_credit_events ADD CONSTRAINT opt_credit_events_kind_check CHECK (kind IN ('verified_payment', 'grant', 'reserve', 'settle', 'release')); END $$;