-- 身份归统一鉴权中心(ADR-012):会话表与岗位授权表退役;员工 id 从此就是 Keycloak 的 sub。 -- -- 从前(ADR-010)是自建账号口令 + 服务端会话表 + 岗位授权(客体三类 × 动作三种)。 -- 现在:后端只验 Bearer JWT;权限只到「端」(design / ops / workbench), -- 角色 → 端是运营中心可改的一张表;名册从 Keycloak 同步、岗位本地指派。 drop table if exists sys.session; drop table if exists sys.position_grant; alter table sys.staff drop column if exists password_hash, add column if not exists email text, add column if not exists roles jsonb not null default '[]'::jsonb, add column if not exists last_seen_at timestamptz, add column if not exists synced_at timestamptz; create table if not exists sys.role_access ( role text primary key, design boolean not null default false, ops boolean not null default false, workbench boolean not null default false, updated_at timestamptz not null default now() ); -- 种子人不是 Keycloak 的人:id 不是 sub,账号还会与 Keycloak 用户名撞唯一索引 —— 清掉。 -- 他们名下的运行数据由 `reset-runs` 清(迁移不碰运行表)。 delete from sys.work_group; delete from sys.staff; -- 身份没了,指着身份的**配置**也不能留: -- `sys.node_owner.staff_id` 是运营配的节点负责人,它排在轮值**之前** —— 留着就是把单派给一个不存在的人; -- `sys.trigger.confirm_staff_id` 是起单确认人,留下 stale id + confirm_required=true, -- 正是「命中的单没人点头、全进死信」那个状态(那也是 setTriggerConfirm 不允许人手工造出来的状态)。 -- 这两张是**配置**表,`reset-runs` 按设计不碰(见 reset-runs.ts 的注释),所以只能在这里收拾。 delete from sys.node_owner; update sys.trigger set confirm_required = false, confirm_staff_id = null where confirm_staff_id is not null;