You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
-- ============================================================
-- 迁移脚本06: 删除is_online列 + 新增在线超时配置项
-- 幂等执行: 先加配置, 再删列( IF EXISTS)
-- ============================================================
-- 1. 新增系统配置项:在线超时阈值(秒)
INSERT INTO cnc_sys_config ( config_key , config_value , value_type , description , updated_at )
SELECT ' online_timeout ' , ' 300 ' , ' number ' , ' 在线超时阈值(秒), 超过此时间未Ping的机床判定为离线 ' , NOW ( )
FROM DUAL
WHERE NOT EXISTS ( SELECT 1 FROM cnc_sys_config WHERE config_key = ' online_timeout ' ) ;
-- 2. 删除 is_online 列( 幂等: IF EXISTS 在 MariaDB 10.0.2+ 支持)
-- 注意: MariaDB 不支持 ALTER TABLE DROP COLUMN IF EXISTS, 用存储过程实现
DROP PROCEDURE IF EXISTS drop_column_if_exists ;
DELIMITER / /
CREATE PROCEDURE drop_column_if_exists ( )
BEGIN
IF EXISTS ( SELECT 1 FROM information_schema . COLUMNS
WHERE TABLE_SCHEMA = DATABASE ( ) AND TABLE_NAME = ' cnc_machine ' AND COLUMN_NAME = ' is_online ' ) THEN
ALTER TABLE cnc_machine DROP COLUMN is_online ;
END IF ;
END / /
DELIMITER ;
CALL drop_column_if_exists ( ) ;
DROP PROCEDURE IF EXISTS drop_column_if_exists ;