From d1978a8571a3b2352ba1bc7b83c9126f82355765 Mon Sep 17 00:00:00 2001 From: OpenAI Codex Date: Wed, 7 Oct 2026 07:00:32 +0000 Subject: [PATCH] fix(migrations): seed log migration flag --- .../202610070004_seed_log_db_migration_flag.sql | 7 +++++++ .../sqlite/202610070004_seed_log_db_migration_flag.sql | 6 ++++++ internal/infra/persistence/migrator/migrator_test.go | 10 +++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 internal/infra/persistence/migrator/goose/postgres/202610070004_seed_log_db_migration_flag.sql create mode 100644 internal/infra/persistence/migrator/goose/sqlite/202610070004_seed_log_db_migration_flag.sql diff --git a/internal/infra/persistence/migrator/goose/postgres/202610070004_seed_log_db_migration_flag.sql b/internal/infra/persistence/migrator/goose/postgres/202610070004_seed_log_db_migration_flag.sql new file mode 100644 index 00000000..c3f2e002 --- /dev/null +++ b/internal/infra/persistence/migrator/goose/postgres/202610070004_seed_log_db_migration_flag.sql @@ -0,0 +1,7 @@ +-- +goose Up +INSERT INTO w_system_configs (key, value, type, visibility, description, created_at, updated_at) +VALUES ('log_db_migration', '', 'system', 0, '日志数据库切换冻结标记', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) +ON CONFLICT (key) DO NOTHING; + +-- +goose Down +-- Keep the runtime migration flag: this row may have existed before this migration. diff --git a/internal/infra/persistence/migrator/goose/sqlite/202610070004_seed_log_db_migration_flag.sql b/internal/infra/persistence/migrator/goose/sqlite/202610070004_seed_log_db_migration_flag.sql new file mode 100644 index 00000000..4fc4cb0d --- /dev/null +++ b/internal/infra/persistence/migrator/goose/sqlite/202610070004_seed_log_db_migration_flag.sql @@ -0,0 +1,6 @@ +-- +goose Up +INSERT OR IGNORE INTO w_system_configs (key, value, type, visibility, description, created_at, updated_at) +VALUES ('log_db_migration', '', 'system', 0, '日志数据库切换冻结标记', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); + +-- +goose Down +-- Keep the runtime migration flag: this row may have existed before this migration. diff --git a/internal/infra/persistence/migrator/migrator_test.go b/internal/infra/persistence/migrator/migrator_test.go index 10a61bb7..8c805e34 100644 --- a/internal/infra/persistence/migrator/migrator_test.go +++ b/internal/infra/persistence/migrator/migrator_test.go @@ -24,7 +24,7 @@ import ( // (初始系统配置 + 各期配置迁移/新增 seed:of_options 迁移、文件白名单、磁盘缓存、 // 登录会话 TTL、升级源、存储、FRPS Web UI、Pages、OpenResty 限流、单 IP 限频、 // 错误页、SW 离线、日志保留期、指标保留期等);新增配置 seed 迁移时需同步更新本常量。 -const expectedMigratedSystemConfigCount = 95 +const expectedMigratedSystemConfigCount = 96 func TestGooseMigrationVersionsAreUniquePerDialect(t *testing.T) { for _, dir := range []string{"goose/postgres", "goose/sqlite"} { @@ -89,6 +89,14 @@ func TestMigrateInitializesSQLiteDatabase(t *testing.T) { t.Errorf("Migrate() w_system_configs count = %d, want %d", systemConfigCount, expectedMigratedSystemConfigCount) } + var logMigrationConfig model.SystemConfig + if err := sqliteDB.Where("key = ?", model.ConfigKeyLogDBMigration).First(&logMigrationConfig).Error; err != nil { + t.Fatalf("Migrate() log migration config error = %v", err) + } + if logMigrationConfig.Value != "" || logMigrationConfig.Type != "system" || logMigrationConfig.Visibility != model.ConfigVisibilityHidden { + t.Errorf("Migrate() log migration config = %+v, want an empty hidden system config", logMigrationConfig) + } + var adminCount int64 if err := sqliteDB.Table("w_users").Where("username = ?", "admin").Count(&adminCount).Error; err != nil { t.Fatalf("Migrate() count admin user error = %v", err)