update staff_roles
set default_entry = case code
  when 'finance_admin' then '/admin/revenue'
  when 'content_admin' then '/admin/site/home'
  when 'agent_staff' then '/staff?mode=tasks'
  when 'consultant' then '/staff?mode=consulting'
  when 'data_service_staff' then '/staff?mode=data-service'
  when 'checkin_staff' then '/admin/events/checkin'
  else default_entry
end,
updated_at = now()
where code in ('finance_admin', 'content_admin', 'agent_staff', 'consultant', 'data_service_staff', 'checkin_staff');

update staff_roles
set permissions = (
  select array_agg(distinct permission order by permission)
  from unnest(permissions || array['course_registration:read', 'course_checkin:update']::text[]) as permission
),
updated_at = now()
where code in ('checkin_staff', 'operations_admin');

update staff_roles
set permissions = array['event:read', 'event_registration:read', 'event_checkin:update', 'course_registration:read', 'course_checkin:update']::text[],
    description = '负责课程和活动报名名单查看与核销。',
    updated_at = now()
where code = 'checkin_staff';
