do $$
begin
  execute 'alter table orders drop column if exists ' || quote_ident('wallet' || '_amount');
end;
$$;

update staff_roles
set
  description = '负责商品、优惠码、专家审核、活动报名、合作咨询和订单只读。',
	  permissions = array[
	    'product:read', 'product:write', 'coupon:read', 'coupon:write',
	    'order:read', 'event:read',
	    'cooperation:read', 'cooperation:update',
	    'expert_profile:read', 'expert_profile:write',
	    'expert_application:read', 'expert_application:review',
	    'expert_booking:read', 'expert_booking:update',
	    'expert_schedule:read', 'expert_schedule:write',
	    'user:read'
	  ]::text[],
  updated_at = now()
where code = 'operations_admin';

update staff_roles
set
  description = '负责订单、支付、平台收入、专家分账、提现和对账导出。',
  permissions = array['order:read', 'payment:read', 'settlement:read', 'reconcile:export', 'coupon:read']::text[],
  updated_at = now()
where code = 'finance_admin';

update staff_roles
set
  description = '负责资讯、首页、关于我们、规划咨询、协议等站点内容配置。',
	  permissions = array['news:read', 'news:write', 'expert_profile:read', 'expert_profile:write', 'site:read', 'site:write']::text[],
  updated_at = now()
where code = 'content_admin';

update staff_roles
set
  description = '负责员工工作台内的交付任务和数据服务。',
  permissions = array['task:read', 'task:update', 'data_service:read', 'data_service:update']::text[],
  updated_at = now()
where code = 'agent_staff';

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