feat(aihr): add tenant organization governance

This commit is contained in:
2026-07-23 15:58:38 +08:00
parent 6a90fd977c
commit 06322c994b
20 changed files with 1619 additions and 3 deletions
@@ -0,0 +1,39 @@
-- 租户与组织两级治理第一期:平台组织目录与租户绑定。
-- 仅新增治理元数据;不修改、迁移或删除 aihr_org_snapshot 历史快照。
CREATE TABLE IF NOT EXISTS `aihr_org_directory` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`source_code` varchar(64) NOT NULL COMMENT '平台组织连接器标识',
`external_id` varchar(128) NOT NULL COMMENT '外部组织稳定ID',
`parent_external_id` varchar(128) DEFAULT NULL COMMENT '外部父组织稳定ID',
`node_type` varchar(32) NOT NULL COMMENT 'GROUP/COMPANY/PROJECT/DEPARTMENT',
`name` varchar(200) NOT NULL COMMENT '组织展示名称',
`path` varchar(2000) NOT NULL COMMENT '稳定ID祖先路径',
`directory_version` char(36) NOT NULL COMMENT '目录刷新版本',
`active` tinyint NOT NULL DEFAULT 1 COMMENT '是否仍在外部组织源有效',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_aihr_org_directory_source_external` (`source_code`, `external_id`),
KEY `idx_aihr_org_directory_source_parent` (`source_code`, `parent_external_id`, `active`),
KEY `idx_aihr_org_directory_source_path` (`source_code`, `path`(255), `active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='平台外部组织目录';
CREATE TABLE IF NOT EXISTS `aihr_tenant_org_binding` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`tenant_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '目标租户编号',
`source_code` varchar(64) NOT NULL COMMENT '平台组织连接器标识',
`root_external_id` varchar(128) NOT NULL COMMENT '绑定根组织稳定ID',
`mode` varchar(32) NOT NULL COMMENT 'EXCLUSIVE/AGGREGATE_ONLY',
`status` varchar(32) NOT NULL COMMENT 'DRAFT/ACTIVE/DISABLED',
`directory_version` char(36) NOT NULL COMMENT '预检所依据的目录版本',
`last_sync_at` datetime DEFAULT NULL COMMENT '最近一次独占范围同步时间',
`create_by` bigint DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` bigint DEFAULT NULL COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_aihr_tenant_org_binding_tenant` (`tenant_id`),
KEY `idx_aihr_tenant_org_binding_source_status` (`source_code`, `status`),
KEY `idx_aihr_tenant_org_binding_root` (`source_code`, `root_external_id`, `status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='租户与组织范围绑定';