CMVR-IOT/sql/workflow_release_version.sql

73 lines
3.2 KiB
MySQL
Raw Normal View History

-- Drafts remain in te_detection_item. Published versions are immutable snapshots.
alter table te_detection_item
add column published_version_id varchar(32) null comment 'Current published workflow version' after flow_data,
add column published_version_no int null comment 'Current published version number' after published_version_id,
add column draft_revision int not null default 0 comment 'Optimistic draft revision' after published_version_no,
add column draft_hash varchar(64) null comment 'Draft SHA-256' after draft_revision,
add column published_draft_hash varchar(64) null comment 'Last published draft SHA-256' after draft_hash,
add index idx_detection_item_published_version (published_version_id);
create table te_detection_item_version (
id varchar(32) not null,
detection_item_id varchar(32) not null,
version_no int not null,
flow_data longtext not null,
config longtext null,
schema_version int not null default 1,
content_hash varchar(64) not null,
source_version_id varchar(32) null,
publish_note varchar(500) null,
create_by varchar(64) null,
create_time datetime null,
update_by varchar(64) null,
update_time datetime null,
remark varchar(500) null,
primary key (id),
unique key uk_detection_item_version (detection_item_id, version_no),
key idx_detection_item_version_item (detection_item_id),
key idx_detection_item_version_source (source_version_id)
) comment='Immutable workflow release history';
-- Every existing non-empty workflow becomes V1. Older releases did not reliably
-- maintain is_deploy, while formal Aima/inspection tasks already executed these definitions.
insert into te_detection_item_version
(id, detection_item_id, version_no, flow_data, config, schema_version,
content_hash, publish_note, create_by, create_time)
select replace(uuid(), '-', ''), id, 1, flow_data, config, 1,
sha2(concat(ifnull(flow_data, ''), '\n', ifnull(config, '')), 256),
'历史流程迁移', create_by, ifnull(update_time, create_time)
from te_detection_item
where flow_data is not null and flow_data <> '';
update te_detection_item item
join te_detection_item_version version
on version.detection_item_id = item.id and version.version_no = 1
set item.published_version_id = version.id,
item.published_version_no = 1,
item.draft_hash = version.content_hash,
item.published_draft_hash = version.content_hash,
item.is_deploy = '0';
update te_detection_item
set draft_hash = sha2(concat(ifnull(flow_data, ''), '\n', ifnull(config, '')), 256)
where draft_hash is null and flow_data is not null;
create table te_task_inst_flow_version (
id varchar(32) not null,
inst_id varchar(32) not null,
item_id varchar(32) not null,
item_order int not null,
item_occurrence int not null,
version_id varchar(32) not null,
version_no int not null,
create_by varchar(64) null,
create_time datetime null,
update_by varchar(64) null,
update_time datetime null,
remark varchar(500) null,
primary key (id),
unique key uk_task_inst_flow_item (inst_id, item_order),
key idx_task_inst_flow_inst (inst_id),
key idx_task_inst_flow_version (version_id)
) comment='Workflow release manifest frozen for a task instance';