am-freescan/am-backend/sql/freescan/002_detection_schema.sql

67 lines
2.7 KiB
MySQL
Raw Normal View History

2026-10-22 16:18:37 +08:00
-- 独立检测配置、不可变发布版本与真实执行日志;租户默认 1。
CREATE TABLE IF NOT EXISTS `lab_detection_item` (
`id` bigint NOT NULL,
`code` varchar(64) NOT NULL,
`name` varchar(128) NOT NULL,
`description` varchar(2048) DEFAULT NULL,
`flow_data` longtext NOT NULL,
`input_schema` text,
`draft_revision` int NOT NULL DEFAULT 1,
`method_ref_id` bigint DEFAULT NULL,
`published_version_id` bigint DEFAULT NULL,
`version_no` int NOT NULL DEFAULT 0,
`creator` varchar(64) DEFAULT '',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updater` varchar(64) DEFAULT '',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted` bit(1) NOT NULL DEFAULT b'0',
`tenant_id` bigint NOT NULL DEFAULT 1,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_detection_code` (`tenant_id`,`code`,`deleted`),
KEY `idx_detection_method` (`method_ref_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='检测项草稿';
CREATE TABLE IF NOT EXISTS `lab_detection_version` (
`id` bigint NOT NULL,
`item_id` bigint NOT NULL,
`version_no` int NOT NULL,
`code` varchar(64) NOT NULL,
`name` varchar(128) NOT NULL,
`flow_data` longtext NOT NULL,
`input_schema` text,
`checksum` varchar(64) NOT NULL,
`creator` varchar(64) DEFAULT '',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updater` varchar(64) DEFAULT '',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted` bit(1) NOT NULL DEFAULT b'0',
`tenant_id` bigint NOT NULL DEFAULT 1,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_detection_version` (`tenant_id`,`item_id`,`version_no`,`deleted`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='检测流程不可变发布版本';
CREATE TABLE IF NOT EXISTS `lab_detection_run` (
`id` bigint NOT NULL,
`item_id` bigint NOT NULL,
`version_id` bigint DEFAULT NULL,
`execution_id` bigint DEFAULT NULL,
`status` varchar(16) NOT NULL,
`flow_data` longtext NOT NULL,
`input_schema` text,
`run_params` longtext,
`output_data` longtext,
`node_logs` longtext,
`error_message` text,
`start_time` bigint DEFAULT NULL,
`end_time` bigint DEFAULT NULL,
`creator` varchar(64) DEFAULT '',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updater` varchar(64) DEFAULT '',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted` bit(1) NOT NULL DEFAULT b'0',
`tenant_id` bigint NOT NULL DEFAULT 1,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_detection_execution` (`tenant_id`,`execution_id`,`deleted`),
KEY `idx_detection_run_item` (`tenant_id`,`item_id`,`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='检测流程真实运行记录';