-- 迁移：admin_users 表新增 roles 字段
-- 原因：登录签发 JWT 时需要携带角色信息，供管理端权限检查使用
-- 回滚：ALTER TABLE admin_users DROP COLUMN IF EXISTS roles;

ALTER TABLE admin_users
    ADD COLUMN IF NOT EXISTS roles text[] NOT NULL DEFAULT '{site_admin}';

COMMENT ON COLUMN admin_users.roles IS '用户角色列表，如 site_admin / tenant_admin';

-- 验证
-- 1. SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_name='admin_users' AND column_name='roles';
-- 2. SELECT id, username, roles FROM admin_users LIMIT 5;
-- 3. SELECT count(*) FROM admin_users WHERE 'site_admin' = ANY(roles);
