设备bug修改 新增设备解绑功能
This commit is contained in:
@@ -10,7 +10,6 @@ CREATE TABLE app_device_binding (
|
||||
device_name_snapshot varchar(255) NULL COMMENT '列表显示名称快照',
|
||||
unbound_time datetime NULL COMMENT '解绑完成时间',
|
||||
unbind_source varchar(16) NULL COMMENT 'DEVICE/APP/ADMIN',
|
||||
unbind_command_id varchar(64) NULL COMMENT '触发解绑的命令编号',
|
||||
cleanup_attempts int NOT NULL DEFAULT 0 COMMENT '清理尝试次数',
|
||||
cleanup_error varchar(500) NULL COMMENT '最近清理错误',
|
||||
create_dept bigint NULL,
|
||||
@@ -32,8 +31,7 @@ CREATE TABLE app_device_binding (
|
||||
CREATE TABLE app_device_unbind_command (
|
||||
id bigint NOT NULL,
|
||||
device_no varchar(64) NOT NULL COMMENT '设备编号',
|
||||
command_id varchar(64) NOT NULL COMMENT '设备解绑命令编号',
|
||||
binding_id varchar(64) NOT NULL COMMENT '命令目标绑定标识',
|
||||
binding_id varchar(64) NOT NULL COMMENT '解绑目标绑定标识',
|
||||
command_status varchar(16) NOT NULL COMMENT 'PROCESSING/APPLIED/STALE/FAILED',
|
||||
message varchar(500) NULL COMMENT '处理结果',
|
||||
attempt_count int NOT NULL DEFAULT 0 COMMENT '处理次数',
|
||||
@@ -44,9 +42,8 @@ CREATE TABLE app_device_unbind_command (
|
||||
update_by bigint NULL,
|
||||
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_app_device_unbind_command (device_no, command_id),
|
||||
KEY idx_app_device_unbind_binding (device_no, binding_id)
|
||||
) COMMENT='设备解绑命令处理记录';
|
||||
UNIQUE KEY uk_app_device_unbind_binding (device_no, binding_id)
|
||||
) COMMENT='设备解绑处理记录';
|
||||
|
||||
-- Existing bindings must re-establish the device-side bindingId before becoming ACTIVE.
|
||||
INSERT INTO app_device_binding (
|
||||
|
||||
35
script/sql/update/remove_device_unbind_command_id.sql
Normal file
35
script/sql/update/remove_device_unbind_command_id.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
-- Device-initiated unbinding is identified by device_no + binding_id.
|
||||
-- Keep the most useful result if the old commandId protocol created duplicate rows.
|
||||
DELETE d
|
||||
FROM app_device_unbind_command d
|
||||
JOIN app_device_unbind_command r
|
||||
ON r.device_no = d.device_no
|
||||
AND r.binding_id = d.binding_id
|
||||
AND (
|
||||
CASE r.command_status
|
||||
WHEN 'APPLIED' THEN 4
|
||||
WHEN 'PROCESSING' THEN 3
|
||||
WHEN 'FAILED' THEN 2
|
||||
WHEN 'STALE' THEN 1
|
||||
ELSE 0
|
||||
END > CASE d.command_status
|
||||
WHEN 'APPLIED' THEN 4
|
||||
WHEN 'PROCESSING' THEN 3
|
||||
WHEN 'FAILED' THEN 2
|
||||
WHEN 'STALE' THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
OR (
|
||||
r.command_status = d.command_status
|
||||
AND r.id < d.id
|
||||
)
|
||||
);
|
||||
|
||||
ALTER TABLE app_device_binding
|
||||
DROP COLUMN unbind_command_id;
|
||||
|
||||
ALTER TABLE app_device_unbind_command
|
||||
DROP INDEX uk_app_device_unbind_command,
|
||||
DROP INDEX idx_app_device_unbind_binding,
|
||||
DROP COLUMN command_id,
|
||||
ADD UNIQUE KEY uk_app_device_unbind_binding (device_no, binding_id);
|
||||
Reference in New Issue
Block a user