feat: Flyway V3迁移(tags列+site_pages+risk_rules表)

This commit is contained in:
mediabot-pt
2026-07-05 21:38:00 +08:00
parent 9eb45e1707
commit 6fb52758c2

View File

@@ -0,0 +1,47 @@
package com.par.core.db.migration;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import java.sql.Statement;
/**
* Flyway V3:新增配置表和字段
* - sites 表增加 tags 列
* - site_pages 表
* - risk_rules 表
*/
public class V3__AddConfigTables extends BaseJavaMigration {
@Override
public void migrate(Context context) throws Exception {
Statement stmt = context.getConnection().createStatement();
// 站点标签
stmt.execute("ALTER TABLE sites ADD COLUMN IF NOT EXISTS tags JSON NULL COMMENT '标签列表' AFTER description");
// 站点页面配置
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', " +
"entries_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_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, " +
"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");
System.out.println("[Flyway V3] Config tables and tags column created");
}
}