fix: 修复risk_rules表site_type字段无默认值导致插入失败问题
This commit is contained in:
@@ -33,10 +33,10 @@ public class FlywayConfig {
|
||||
"created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
||||
"INDEX idx_site_id (site_id, deleted)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
|
||||
stmt.execute("CREATE TABLE IF NOT EXISTS risk_rules (" +
|
||||
"id BIGINT AUTO_INCREMENT PRIMARY KEY, site_type VARCHAR(32) NOT NULL, version INT NOT NULL DEFAULT 1, " +
|
||||
"id BIGINT AUTO_INCREMENT PRIMARY KEY, site_type VARCHAR(32) DEFAULT NULL, site_id VARCHAR(255) DEFAULT NULL, version INT NOT NULL DEFAULT 1, " +
|
||||
"rules_json LONGTEXT NOT NULL, deleted TINYINT NOT NULL DEFAULT 0, " +
|
||||
"created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
||||
"INDEX idx_site_type (site_type, deleted)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
|
||||
"INDEX idx_site_type (site_type, deleted), INDEX idx_risk_rules_site_id (site_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
|
||||
try { stmt.execute("ALTER TABLE sites ADD COLUMN version INT NOT NULL DEFAULT 1"); } catch (Exception ex) { log.debug("version may exist"); }
|
||||
log.info("V15 tables initialized");
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -4,6 +4,12 @@ PREPARE stmt FROM @sqlstmt;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @site_type_nullable := (SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'risk_rules' AND column_name = 'site_type');
|
||||
SET @site_type_sqlstmt := IF(@site_type_nullable = 'NO', 'ALTER TABLE risk_rules MODIFY COLUMN site_type VARCHAR(32) DEFAULT NULL', 'DO 0');
|
||||
PREPARE site_type_stmt FROM @site_type_sqlstmt;
|
||||
EXECUTE site_type_stmt;
|
||||
DEALLOCATE PREPARE site_type_stmt;
|
||||
|
||||
SET @idx_exist := (SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema = DATABASE() AND table_name = 'risk_rules' AND index_name = 'idx_risk_rules_site_id');
|
||||
SET @idx_sqlstmt := IF(@idx_exist = 0, 'CREATE INDEX idx_risk_rules_site_id ON risk_rules(site_id)', 'DO 0');
|
||||
PREPARE idx_stmt FROM @idx_sqlstmt;
|
||||
|
||||
Reference in New Issue
Block a user