ALTER TABLE gateway.api_keys
    ADD COLUMN IF NOT EXISTS monthly_token_quota bigint NOT NULL DEFAULT 0;

ALTER TABLE gateway.api_keys
    DROP CONSTRAINT IF EXISTS api_keys_monthly_token_quota_check;

ALTER TABLE gateway.api_keys
    ADD CONSTRAINT api_keys_monthly_token_quota_check
        CHECK (monthly_token_quota BETWEEN 0 AND 1000000000000000);

COMMENT ON COLUMN gateway.api_keys.monthly_token_quota IS
    'Maximum input plus output tokens per UTC calendar month; zero means unlimited.';
