fastbee/sql/fastbee2.4-upgrade-v2.5.sql

127 lines
13 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 数据库版本升级脚本
-- 适用于fastbee2.4版本到fastbee2.5版本的数据库升级
-- 注意:请在备份好数据库后再进行升级操作
-- modbus产品改造
CREATE TABLE `iot_product_modbus_job` (
`task_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '任务id',
`job_name` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '任务名称',
`product_id` bigint(20) NOT NULL COMMENT '产品id',
`command` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '指令',
`status` char(1) COLLATE utf8_unicode_ci NOT NULL COMMENT '状态(0正常 1暂停)',
`create_by` varchar(64) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '创建者',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`remark` varchar(500) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '备注信息',
PRIMARY KEY (`task_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='产品轮训任务列表';
CREATE TABLE `iot_product_sub_gateway` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '业务id',
`gw_product_id` bigint(20) NOT NULL COMMENT '网关产品id',
`sub_product_id` bigint(20) NOT NULL COMMENT '子产品id',
`slave_id` int(6) DEFAULT NULL COMMENT '从机地址',
`create_by` varchar(64) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_by` varchar(64) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '更新者',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`remark` varchar(500) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='网关与子产品关联表';
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (3363, '产品modbus关联子产品', 2043, 16, '', NULL, NULL, 1, 0, 'F', '0', '0', 'productModbus:gateway:list', '#', 'admin', '2024-09-11 14:44:04', 'admin', '2024-09-11 14:48:00', '');
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (3364, '新增产品modbus关联子产品', 3363, 0, '', NULL, NULL, 1, 0, 'F', '0', '0', 'productModbus:gateway:add', '#', 'admin', '2024-09-11 14:45:27', '', NULL, '');
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (3365, '修改产品modbus关联子产品', 3363, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'productModbus:gateway:edit', '#', 'admin', '2024-09-11 14:45:57', '', NULL, '');
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (3366, '删除产品modbus关联子产品', 3363, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'productModbus:gateway:remove', '#', 'admin', '2024-09-11 14:46:20', '', NULL, '');
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (3367, '产品modbus轮询任务', 2043, 17, '', NULL, NULL, 1, 0, 'F', '0', '0', 'productModbus:job:list', '#', 'admin', '2024-09-11 14:47:40', 'admin', '2024-09-11 14:48:08', '');
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (3368, '新增产品modbus轮询任务', 3367, 0, '', NULL, NULL, 1, 0, 'F', '0', '0', 'productModbus:job:add', '#', 'admin', '2024-09-11 14:48:35', '', NULL, '');
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (3369, '修改产品modbus轮询任务', 3367, 1, '', NULL, NULL, 1, 0, 'F', '0', '0', 'productModbus:job:edit', '#', 'admin', '2024-09-11 14:48:54', '', NULL, '');
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (3370, '删除产品modbus轮询任务', 3367, 2, '', NULL, NULL, 1, 0, 'F', '0', '0', 'productModbus:job:remove', '#', 'admin', '2024-09-11 14:54:59', '', NULL, '');
INSERT INTO `sys_menu_translate` (`id`, `zh_cn`, `en_us`) VALUES (3363, '产品modbus关联子产品', 'Product Modbus related sub products');
INSERT INTO `sys_menu_translate` (`id`, `zh_cn`, `en_us`) VALUES (3364, '新增产品modbus关联子产品', 'New product Modbus associated sub product');
INSERT INTO `sys_menu_translate` (`id`, `zh_cn`, `en_us`) VALUES (3365, '修改产品modbus关联子产品', 'Modify product Modbus associated sub products');
INSERT INTO `sys_menu_translate` (`id`, `zh_cn`, `en_us`) VALUES (3366, '删除产品modbus关联子产品', 'Delete product Modbus associated sub products');
INSERT INTO `sys_menu_translate` (`id`, `zh_cn`, `en_us`) VALUES (3367, '产品modbus轮询任务', 'Product Modbus polling task');
INSERT INTO `sys_menu_translate` (`id`, `zh_cn`, `en_us`) VALUES (3368, '新增产品modbus轮询任务', 'New product Modbus polling task');
INSERT INTO `sys_menu_translate` (`id`, `zh_cn`, `en_us`) VALUES (3369, '修改产品modbus轮询任务', 'Modify product Modbus polling task');
INSERT INTO `sys_menu_translate` (`id`, `zh_cn`, `en_us`) VALUES (3370, '删除产品modbus轮询任务', 'Delete product Modbus polling task');
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (3371, 'modbus配置导入', 3298, 6, '', NULL, NULL, 1, 0, 'F', '0', '0', 'modbus:config:import', '#', 'admin', '2024-09-11 16:10:35', '', NULL, '');
INSERT INTO `sys_menu_translate` (`id`, `zh_cn`, `en_us`) VALUES (3371, 'modbus配置导入', 'Modbus configuration import');
-- 协议管理
ALTER TABLE `iot_protocol`
ADD COLUMN `display` tinyint(2) NOT NULL DEFAULT 1 COMMENT '显示,1-显示;0-不显示';
ALTER TABLE `iot_protocol`
ADD COLUMN `data_format` text NULL COMMENT '协议数据格式';
ALTER TABLE `iot_device`
add COLUMN `wireless_version` float(11) null COMMENT '分包拉取固件版本';
ALTER TABLE `bridge`
MODIFY COLUMN `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
MODIFY COLUMN `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';
ALTER TABLE `iot_firmware`
ADD COLUMN `firmware_type` tinyint(2) NULL DEFAULT NULL COMMENT '1,二进制包升级2.http升级' AFTER `firmware_name`,
ADD COLUMN `byte_size` int(5) NULL DEFAULT NULL COMMENT '分包字节大小' AFTER `version`;
-- 修复国际化物模型表遗漏字段
ALTER TABLE `iot_things_model_translate`
ADD COLUMN `product_id` bigint(20) NULL DEFAULT NULL COMMENT '产品ID';
-- 设备级modbus配置表(用于设备覆盖产品模板)
CREATE TABLE IF NOT EXISTS `iot_device_modbus_config` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '业务id',
`device_id` bigint(20) NOT NULL COMMENT '所属设备id',
`product_id` bigint(20) NOT NULL COMMENT '所属产品id(兜底物模型)',
`identifier` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '关联属性',
`slave` int(10) DEFAULT NULL COMMENT '从机地址',
`address` int(10) NOT NULL COMMENT '寄存器地址',
`is_readonly` tinyint(1) NOT NULL COMMENT '是否只读(0-否,1-是)',
`data_type` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT 'modbus数据类型',
`quantity` int(2) DEFAULT NULL COMMENT '读取个数',
`type` tinyint(1) NOT NULL COMMENT '寄存器类型 1-IO寄存器 2-数据寄存器',
`bit_order` int(2) DEFAULT NULL COMMENT 'bit位排序',
`sort` int(6) DEFAULT NULL COMMENT '排序',
`del_flag` char(1) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
`create_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '' COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '' COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`remark` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uk_device_identifier` (`device_id`,`identifier`),
KEY `idx_device_address_bit` (`device_id`,`address`,`bit_order`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC COMMENT='设备级modbus配置表(覆盖产品模板)';
-- ----------------------------
-- 设备级modbus配置参数表 iot_device_modbus_params
-- 继承自产品级 iot_modbus_params,用于设备级别的个性化配置
-- @author Sumuxi
-- @date 2026/1/14
-- ----------------------------
DROP TABLE IF EXISTS `iot_device_modbus_params`;
CREATE TABLE `iot_device_modbus_params` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '业务id',
`device_id` bigint(20) NOT NULL COMMENT '设备id',
`product_id` bigint(20) NOT NULL COMMENT '产品id',
`poll_type` tinyint(1) NULL DEFAULT NULL COMMENT '是否启动云端轮训(0-云端轮训,1-边缘采集)',
`slave_id` int(3) NULL DEFAULT NULL COMMENT '默认的子设备地址',
`status_deter` tinyint(1) NULL DEFAULT NULL COMMENT '子设备状态判断方式 1-设备数据 2- 网关',
`deter_timer` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '设备数据来判断子设备状态的时长(s)',
`poll_length` int(3) NULL DEFAULT NULL COMMENT '批量读取的个数',
`create_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '更新者',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`remark` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uk_device_id` (`device_id`) USING BTREE COMMENT '设备唯一索引',
KEY `idx_product_id` (`product_id`) USING BTREE COMMENT '产品id索引'
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '设备modbus配置参数' ROW_FORMAT = DYNAMIC;