fix(iam): 修复仓库角色统一迁移执行

This commit is contained in:
2026-08-10 13:00:13 +08:00
parent 64ba5ae249
commit 20996b050b
3 changed files with 88 additions and 31 deletions
@@ -85,19 +85,23 @@ INSERT INTO tmp_phase3_warehouse_role_permission (role_code, permission_code) VA
('WAREHOUSE_TALLY', 'platform:firstleg:pda:view'),
('WAREHOUSE_TALLY', 'platform:firstleg:pda:review'),
('WAREHOUSE_TALLY', 'platform:firstleg:inbound:loading:view'),
('WAREHOUSE_TALLY', 'platform:firstleg:inbound:loading:edit'),
('WAREHOUSE_TALLY', 'platform:firstleg:inbound:picking:view');
('WAREHOUSE_TALLY', 'platform:firstleg:inbound:loading:edit');
DROP PROCEDURE IF EXISTS assert_phase3_warehouse_role_permissions_available;
DELIMITER $$
CREATE PROCEDURE assert_phase3_warehouse_role_permissions_available()
BEGIN
IF (SELECT COUNT(*) FROM tmp_phase3_warehouse_role_permission
WHERE role_code = 'WAREHOUSE_OPERATOR') <> 5
OR (SELECT COUNT(*) FROM tmp_phase3_warehouse_role_permission
WHERE role_code = 'WAREHOUSE_PICKER') <> 2
OR (SELECT COUNT(*) FROM tmp_phase3_warehouse_role_permission
WHERE role_code = 'WAREHOUSE_TALLY') <> 12 THEN
DECLARE operator_permission_count INT DEFAULT 0;
DECLARE picker_permission_count INT DEFAULT 0;
DECLARE tally_permission_count INT DEFAULT 0;
SELECT COALESCE(SUM(role_code = 'WAREHOUSE_OPERATOR'), 0),
COALESCE(SUM(role_code = 'WAREHOUSE_PICKER'), 0),
COALESCE(SUM(role_code = 'WAREHOUSE_TALLY'), 0)
INTO operator_permission_count, picker_permission_count, tally_permission_count
FROM tmp_phase3_warehouse_role_permission;
IF operator_permission_count <> 5
OR picker_permission_count <> 2
OR tally_permission_count <> 12 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = '仓库角色初始化失败:角色权限组合数量不符合预期';
END IF;
@@ -17,7 +17,14 @@ class WarehouseRoleSqlContractTest {
@Test
void unifiedDeploymentContainsTheSameWarehouseRoleContract() throws Exception {
assertWarehouseRoleContract(unifiedSql());
String sql = unifiedSql();
assertWarehouseRoleContract(sql);
assertThat(sql)
.doesNotContain("\n ADD COLUMN IF NOT EXISTS")
.doesNotContain("DROP CHECK IF EXISTS");
assertThat(sql.lastIndexOf("SELECT 'PASS' AS migration_status"))
.isGreaterThan(sql.indexOf("CALL assert_phase3_warehouse_roles_ready()"));
assertThat(sql.trim()).endsWith("AS message;");
}
private static void assertWarehouseRoleContract(String sql) {
@@ -32,9 +39,9 @@ class WarehouseRoleSqlContractTest {
.contains("'WAREHOUSE_TALLY', 'platform:firstleg:pda:review'")
.contains("'WAREHOUSE_TALLY', 'platform:firstleg:inbound:loading:edit'")
.contains("'WAREHOUSE_OPERATOR', 'platform:firstleg:inbound:loading:edit'")
.contains("WHERE role_code = 'WAREHOUSE_OPERATOR') <> 5")
.contains("WHERE role_code = 'WAREHOUSE_PICKER') <> 2")
.contains("WHERE role_code = 'WAREHOUSE_TALLY') <> 12")
.contains("operator_permission_count <> 5")
.contains("picker_permission_count <> 2")
.contains("tally_permission_count <> 12")
.contains("依赖的三期平台权限尚未完整部署")
.contains("DELETE role_permission")
.contains("expected.permission_code IS NULL")
@@ -61,6 +68,7 @@ class WarehouseRoleSqlContractTest {
.doesNotContain("platform:firstleg:outbound-dispatch:confirm");
assertThat(roleGrantBlock(sql, "WAREHOUSE_TALLY"))
.doesNotContain("platform:firstleg:inbound:loading:complete")
.doesNotContain("platform:firstleg:inbound:picking:view")
.doesNotContain("platform:firstleg:outbound-dispatch:confirm");
assertThat(sql)
.doesNotContain("'WAREHOUSE_OPERATOR', 'platform:firstleg:pda:assign'")