From ea7658815a1a658a625b4b9f6ab611869a4c739d Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 4 Aug 2026 12:49:58 +0800 Subject: [PATCH] fix(migration): quote reserved authorization column --- docs/changelog/index.md | 2 ++ .../202608040001_create_cloudflare_pointing.sql | 2 +- .../infra/persistence/migrator/migrator_test.go | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/changelog/index.md b/docs/changelog/index.md index ad303a7c..832fead3 100644 --- a/docs/changelog/index.md +++ b/docs/changelog/index.md @@ -49,6 +49,8 @@ sidebar: false ### 修复 +- 修复 Cloudflare DNS 指向功能在 PostgreSQL 初始化迁移时因 `authorization` 保留关键字导致启动失败的问题。 + - 修复 IP 组自动抓取使用预设规则时未写入 `ttl` 字段的问题,避免配置 JSON 缺少封禁时长。 - 修复限流相关迁移中表名错误,确保升级脚本正确执行。 diff --git a/internal/infra/persistence/migrator/goose/postgres/202608040001_create_cloudflare_pointing.sql b/internal/infra/persistence/migrator/goose/postgres/202608040001_create_cloudflare_pointing.sql index e7bff812..87b60df6 100644 --- a/internal/infra/persistence/migrator/goose/postgres/202608040001_create_cloudflare_pointing.sql +++ b/internal/infra/persistence/migrator/goose/postgres/202608040001_create_cloudflare_pointing.sql @@ -3,7 +3,7 @@ CREATE TABLE IF NOT EXISTS of_cf_connections ( id BIGSERIAL PRIMARY KEY, source VARCHAR(32) NOT NULL DEFAULT '', dns_account_id BIGINT, - authorization TEXT NOT NULL DEFAULT '', + "authorization" TEXT NOT NULL DEFAULT '', status VARCHAR(16) NOT NULL DEFAULT '', verified_at TIMESTAMPTZ, created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, diff --git a/internal/infra/persistence/migrator/migrator_test.go b/internal/infra/persistence/migrator/migrator_test.go index d58392a2..33d3e867 100644 --- a/internal/infra/persistence/migrator/migrator_test.go +++ b/internal/infra/persistence/migrator/migrator_test.go @@ -5,6 +5,7 @@ package migrator import ( "context" + "strings" "testing" "github.com/Rain-kl/Wavelet/internal/infra/config" @@ -93,6 +94,9 @@ func TestMigrateInitializesSQLiteDatabase(t *testing.T) { t.Errorf("Migrate() did not create %s", table) } } + if !sqliteDB.Migrator().HasColumn("of_cf_connections", "authorization") { + t.Error("Migrate() did not create of_cf_connections.authorization") + } if sqliteDB.Migrator().HasTable("of_managed_domains") { t.Error("Migrate() should drop of_managed_domains after phase-2 cleanup") } @@ -140,6 +144,16 @@ func TestMigrateInitializesSQLiteDatabase(t *testing.T) { } } +func TestCloudflarePointingPostgresMigrationQuotesAuthorizationColumn(t *testing.T) { + content, err := migrationFS.ReadFile("goose/postgres/202608040001_create_cloudflare_pointing.sql") + if err != nil { + t.Fatalf("read Cloudflare pointing migration: %v", err) + } + if !strings.Contains(string(content), `"authorization" TEXT NOT NULL DEFAULT ''`) { + t.Error("Cloudflare pointing PostgreSQL migration must quote reserved column authorization") + } +} + func TestMigrateClearsStaleSystemConfigCache(t *testing.T) { sqliteDB, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{ DisableForeignKeyConstraintWhenMigrating: true,