From 3d6c527b64f4904ebdae5a206a4aa8ffd074408d Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 24 Feb 2026 13:09:06 +0100 Subject: [PATCH] fix: cast bucket_configuration to text in postgres catchup query The new catchup migration compared the postgres JSON column with string literals using !=, which fails in migration smoke tests. Use a PostgreSQL-specific WHERE clause with ::text and cover it with unit tests. --- pkg/migration/20260224122023.go | 10 +++++++++- pkg/migration/20260224122023_test.go | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/pkg/migration/20260224122023.go b/pkg/migration/20260224122023.go index 498c9c6c4..7eed66b89 100644 --- a/pkg/migration/20260224122023.go +++ b/pkg/migration/20260224122023.go @@ -136,13 +136,21 @@ func convertBucketConfigurations20260224122023(configs []*bucketConfigFix2026022 return converted, changed, nil } +func bucketConfigurationWhereClause20260224122023(dbType schemas.DBType) string { + if dbType == schemas.POSTGRES { + return "bucket_configuration IS NOT NULL AND bucket_configuration::text != '' AND bucket_configuration::text != '[]' AND bucket_configuration::text != 'null'" + } + + return "bucket_configuration IS NOT NULL AND bucket_configuration != '' AND bucket_configuration != '[]' AND bucket_configuration != 'null'" +} + func init() { migrations = append(migrations, &xormigrate.Migration{ ID: "20260224122023", Description: "comprehensive catchup for bucket_configuration and view filter format conversions", Migrate: func(tx *xorm.Engine) (err error) { allViews := []*projectViewFix20260224122023{} - err = tx.Where("bucket_configuration IS NOT NULL AND bucket_configuration != '' AND bucket_configuration != '[]' AND bucket_configuration != 'null'"). + err = tx.Where(bucketConfigurationWhereClause20260224122023(tx.Dialect().URI().DBType)). Find(&allViews) if err != nil { return diff --git a/pkg/migration/20260224122023_test.go b/pkg/migration/20260224122023_test.go index 89b37f6af..4344ff7a3 100644 --- a/pkg/migration/20260224122023_test.go +++ b/pkg/migration/20260224122023_test.go @@ -19,6 +19,8 @@ package migration import ( "encoding/json" "testing" + + "xorm.io/xorm/schemas" ) func TestConvertBucketConfigurations20260224122023_ConvertsStringAndPreservesObject(t *testing.T) { @@ -81,3 +83,21 @@ func TestConvertBucketConfigurations20260224122023_NoChangesWhenAlreadyObjects(t t.Fatalf("unexpected conversion result: %#v", converted) } } + +func TestBucketConfigurationWhereClause20260224122023_PostgresUsesTextCast(t *testing.T) { + got := bucketConfigurationWhereClause20260224122023(schemas.POSTGRES) + want := "bucket_configuration IS NOT NULL AND bucket_configuration::text != '' AND bucket_configuration::text != '[]' AND bucket_configuration::text != 'null'" + + if got != want { + t.Fatalf("unexpected clause\nwant: %s\ngot: %s", want, got) + } +} + +func TestBucketConfigurationWhereClause20260224122023_DefaultDoesNotCast(t *testing.T) { + got := bucketConfigurationWhereClause20260224122023(schemas.SQLITE) + want := "bucket_configuration IS NOT NULL AND bucket_configuration != '' AND bucket_configuration != '[]' AND bucket_configuration != 'null'" + + if got != want { + t.Fatalf("unexpected clause\nwant: %s\ngot: %s", want, got) + } +}