fix: MySQL8.4不支持IF NOT EXISTS改为ALTER TABLE单独try-catch
This commit is contained in:
@@ -24,9 +24,9 @@ public class FlywayConfig {
|
|||||||
log.info("Flyway migrate: applying pending migrations...");
|
log.info("Flyway migrate: applying pending migrations...");
|
||||||
flyway.migrate();
|
flyway.migrate();
|
||||||
|
|
||||||
// V15: tags 列 + 新表(Flyway Java 迁移可能因包路径问题不触达)
|
// V15: tags 列 + 新表
|
||||||
try (var conn = dataSource.getConnection(); var stmt = conn.createStatement()) {
|
try (var conn = dataSource.getConnection(); var stmt = conn.createStatement()) {
|
||||||
stmt.execute("ALTER TABLE sites ADD COLUMN IF NOT EXISTS tags JSON NULL COMMENT '标签列表' AFTER description");
|
try { stmt.execute("ALTER TABLE sites ADD COLUMN tags JSON NULL COMMENT '标签列表' AFTER description"); } catch (Exception ex) { log.debug("tags may exist: {}", ex.getMessage()); }
|
||||||
stmt.execute("CREATE TABLE IF NOT EXISTS site_pages (" +
|
stmt.execute("CREATE TABLE IF NOT EXISTS site_pages (" +
|
||||||
"id BIGINT AUTO_INCREMENT PRIMARY KEY, site_id VARCHAR(64) NOT NULL, version VARCHAR(20) NOT NULL DEFAULT '1.0.0', " +
|
"id BIGINT AUTO_INCREMENT PRIMARY KEY, site_id VARCHAR(64) NOT NULL, version VARCHAR(20) NOT NULL DEFAULT '1.0.0', " +
|
||||||
"entries_json LONGTEXT NOT NULL, deleted TINYINT NOT NULL DEFAULT 0, " +
|
"entries_json LONGTEXT NOT NULL, deleted TINYINT NOT NULL DEFAULT 0, " +
|
||||||
@@ -37,9 +37,9 @@ public class FlywayConfig {
|
|||||||
"rules_json LONGTEXT NOT NULL, deleted TINYINT NOT NULL DEFAULT 0, " +
|
"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, " +
|
"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)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
|
||||||
log.info("V15 tables initialized via FlywayConfig");
|
log.info("V15 tables initialized");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("V15 migration failed (may already exist): {}", e.getMessage());
|
log.error("V15 migration failed: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user