u
This commit is contained in:
1 parent
7bd5f1dde9
commit
f3936cec61
70 files changed
+13074
-187
No files matched your search
@@ -0,0 +1,41 @@
|
||||
/* ============================================================
|
||||
工作流补丁:补齐缺失索引
|
||||
------------------------------------------------------------
|
||||
来源:迁移评审发现的三处全表扫描 / 排序开销。
|
||||
幂等:按 sys.indexes 判断,可重复执行。
|
||||
============================================================ */
|
||||
|
||||
/* 发布路径:allowedConditionFields / deleteDefinition 都按 b_version_id 直查,
|
||||
而原有索引 ix_wf_binding_select 不以 b_version_id 打头 → 每次发布必扫。 */
|
||||
if not exists (select 1 from sys.indexes
|
||||
where name = N'ix_wf_binding_version'
|
||||
and object_id = object_id(N'dbo.wf_binding'))
|
||||
begin
|
||||
create index ix_wf_binding_version
|
||||
on dbo.wf_binding (b_version_id)
|
||||
include (b_module_id, b_canuse, b_priority);
|
||||
print N'已创建 ix_wf_binding_version';
|
||||
end
|
||||
go
|
||||
|
||||
/* 「我已处理」列表按 b_completed_by 过滤,原 wf_task 只按 assignee/instance/due 建索引。 */
|
||||
if not exists (select 1 from sys.indexes
|
||||
where name = N'ix_wf_task_completed_by'
|
||||
and object_id = object_id(N'dbo.wf_task'))
|
||||
begin
|
||||
create index ix_wf_task_completed_by
|
||||
on dbo.wf_task (b_completed_by, b_completed_at desc);
|
||||
print N'已创建 ix_wf_task_completed_by';
|
||||
end
|
||||
go
|
||||
|
||||
/* 串行会签提升 / cancelSiblingTasks 都按 (node_run, status, seq) 取行。 */
|
||||
if not exists (select 1 from sys.indexes
|
||||
where name = N'ix_wf_task_node_run'
|
||||
and object_id = object_id(N'dbo.wf_task'))
|
||||
begin
|
||||
create index ix_wf_task_node_run
|
||||
on dbo.wf_task (b_node_run_id, b_status, b_seq, b_id);
|
||||
print N'已创建 ix_wf_task_node_run';
|
||||
end
|
||||
go
|
||||
@@ -0,0 +1,81 @@
|
||||
/* ============================================================
|
||||
工作流补丁:恢复缺失的「筛选唯一索引」
|
||||
------------------------------------------------------------
|
||||
背景:现有 G3ERP 库的 wf_* 表已建,但基础 DDL 里的 4 个筛选唯一索引
|
||||
(unique filtered index)在库中并不存在。缺了它们意味着:
|
||||
|
||||
- 同一定义可以并存多条草稿(应用层靠代码判,DB 层无兜底);
|
||||
- submit 的幂等键 b_idempotency_key 不生效 —— 重复提交不会被拦;
|
||||
- wf_action.b_request_id 不生效 —— 重复审批不会被拦;
|
||||
- 同一模块/事件下可以有两条同优先级启用绑定。
|
||||
|
||||
本脚本幂等;创建前先查重,有冲突则 RAISERROR 报错而不是静默失败。
|
||||
============================================================ */
|
||||
|
||||
if not exists (select 1 from sys.indexes
|
||||
where name = N'ux_wf_version_draft' and object_id = object_id(N'dbo.wf_version'))
|
||||
begin
|
||||
if exists (select 1 from dbo.wf_version
|
||||
where b_status = 'draft'
|
||||
group by b_definition_id having count(1) > 1)
|
||||
raiserror(N'存在同一流程定义的多条草稿版本,无法创建 ux_wf_version_draft,请先清理', 16, 1);
|
||||
else
|
||||
begin
|
||||
create unique index ux_wf_version_draft
|
||||
on dbo.wf_version (b_definition_id)
|
||||
where b_status = 'draft';
|
||||
print N'已创建 ux_wf_version_draft';
|
||||
end
|
||||
end
|
||||
go
|
||||
|
||||
if not exists (select 1 from sys.indexes
|
||||
where name = N'ux_wf_binding_active_priority' and object_id = object_id(N'dbo.wf_binding'))
|
||||
begin
|
||||
if exists (select 1 from dbo.wf_binding
|
||||
where b_canuse = 1
|
||||
group by b_module_id, b_event, b_priority having count(1) > 1)
|
||||
raiserror(N'存在同一模块/事件下同优先级的启用绑定,无法创建 ux_wf_binding_active_priority,请先清理', 16, 1);
|
||||
else
|
||||
begin
|
||||
create unique index ux_wf_binding_active_priority
|
||||
on dbo.wf_binding (b_module_id, b_event, b_priority)
|
||||
where b_canuse = 1;
|
||||
print N'已创建 ux_wf_binding_active_priority';
|
||||
end
|
||||
end
|
||||
go
|
||||
|
||||
if not exists (select 1 from sys.indexes
|
||||
where name = N'ux_wf_instance_idempotency' and object_id = object_id(N'dbo.wf_instance'))
|
||||
begin
|
||||
if exists (select 1 from dbo.wf_instance
|
||||
where b_idempotency_key is not null
|
||||
group by b_module_id, b_business_id, b_idempotency_key having count(1) > 1)
|
||||
raiserror(N'存在重复的幂等键,无法创建 ux_wf_instance_idempotency,请先清理', 16, 1);
|
||||
else
|
||||
begin
|
||||
create unique index ux_wf_instance_idempotency
|
||||
on dbo.wf_instance (b_module_id, b_business_id, b_idempotency_key)
|
||||
where b_idempotency_key is not null;
|
||||
print N'已创建 ux_wf_instance_idempotency';
|
||||
end
|
||||
end
|
||||
go
|
||||
|
||||
if not exists (select 1 from sys.indexes
|
||||
where name = N'ux_wf_action_request' and object_id = object_id(N'dbo.wf_action'))
|
||||
begin
|
||||
if exists (select 1 from dbo.wf_action
|
||||
where b_request_id is not null
|
||||
group by b_request_id having count(1) > 1)
|
||||
raiserror(N'存在重复的请求 ID,无法创建 ux_wf_action_request,请先清理', 16, 1);
|
||||
else
|
||||
begin
|
||||
create unique index ux_wf_action_request
|
||||
on dbo.wf_action (b_request_id)
|
||||
where b_request_id is not null;
|
||||
print N'已创建 ux_wf_action_request';
|
||||
end
|
||||
end
|
||||
go
|
||||
Reference in new issue
Block a user