DROP TABLE IF EXISTS app_user;

-- Demote any self-registered keys before restoring the narrower tier check.
UPDATE api_key SET tier = 'free' WHERE tier = 'registered';

ALTER TABLE api_key DROP CONSTRAINT IF EXISTS api_key_tier_chk;
ALTER TABLE api_key ADD CONSTRAINT api_key_tier_chk
    CHECK (tier IN ('free', 'partner', 'internal'));

ALTER TABLE api_key DROP COLUMN IF EXISTS quota_total;
