fix(migrations): seed log migration flag

This commit is contained in:
OpenAI Codex
2026-10-07 07:00:32 +00:00
parent 4e584d2e2d
commit d1978a8571
3 changed files with 22 additions and 1 deletions
@@ -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.
@@ -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.
@@ -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)