统一鉴权中心接入(ADR-012):org 重写为 Keycloak 身份 + 角色→端;中间件按路由归属统一判;口令/会话/岗位授权退役;迁移 0032

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015kAzS35kMnZNt4YGgJXtfw
This commit is contained in:
xcs
2026-08-25 17:40:55 +08:00
co-authored by Claude Opus 5
parent 81a185cd61
commit dd31b91829
38 changed files with 1236 additions and 1485 deletions
+27
View File
@@ -0,0 +1,27 @@
-- 身份归统一鉴权中心(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;