This repository has been archived on 2026-09-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
BPOS-TMP-REPO/db/migrations/0032_keycloak_identity.sql
xcsandClaude Opus 5 8dc71db9d8 评审两条 Important:迁移连带清掉指向身份的两张配置表;治理台收件人为空时出声
节点负责人(排在轮值之前)与触发器确认人都是无 FK 的裸 staff id,而 reset-runs 按设计
不碰配置表 —— 切换后留着就是「把单派给不存在的人」与「命中的单没人点头全进死信」。
governanceStaff 在全新安装(还没人以 admin 登录过)时是空集,而调用方是死信通知:
收件人为空原本会静默丢掉「出事了」这件事,现在留一条说清怎么办的话。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015kAzS35kMnZNt4YGgJXtfw
2026-08-25 17:57:21 +08:00

36 lines
1.9 KiB
SQL

-- 身份归统一鉴权中心(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;