alter table public.platform_users
  add column if not exists platform_permissions jsonb not null default '{}'::jsonb;

update public.platform_users
set platform_permissions = '{"*":true}'::jsonb
where primary_role = 'platform_admin'
  and (platform_permissions = '{}'::jsonb or platform_permissions is null);

create index if not exists idx_platform_users_platform_permissions_gin
  on public.platform_users using gin (platform_permissions);
