From 6fb52758c2561bc9945d92268b0253efecafff7e Mon Sep 17 00:00:00 2001 From: mediabot-pt <295750538+mediabot-pt@users.noreply.github.com> Date: Sun, 5 Jul 2026 21:38:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Flyway=20V3=E8=BF=81=E7=A7=BB(tags?= =?UTF-8?q?=E5=88=97+site=5Fpages+risk=5Frules=E8=A1=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/migration/V3__AddConfigTables.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 par-core/src/main/java/com/par/core/db/migration/V3__AddConfigTables.java diff --git a/par-core/src/main/java/com/par/core/db/migration/V3__AddConfigTables.java b/par-core/src/main/java/com/par/core/db/migration/V3__AddConfigTables.java new file mode 100644 index 0000000..4b28a17 --- /dev/null +++ b/par-core/src/main/java/com/par/core/db/migration/V3__AddConfigTables.java @@ -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"); + } +}