-- Role-scoped AI credit packages, mirroring pricing_packages' existing
-- role_key convention (though as an array here since one AI package can
-- reasonably apply to several roles at once, unlike TraceCoin packages
-- which are one row per role). Empty array = visible/purchasable by every
-- role (the default, matching today's actual behavior for the 4 existing
-- packages so nothing changes for them until an admin opts them into
-- specific roles).

BEGIN;

ALTER TABLE ai_credit_packages
    ADD COLUMN IF NOT EXISTS applicable_roles TEXT[] NOT NULL DEFAULT '{}';

CREATE INDEX IF NOT EXISTS idx_ai_credit_packages_applicable_roles
    ON ai_credit_packages USING GIN (applicable_roles);

COMMIT;
