设备bug修改 新增设备解绑功能
This commit is contained in:
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