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.
This commit is contained in:
kolaente 2026-02-24 13:09:06 +01:00
parent 99ac3e65b8
commit 3d6c527b64
2 changed files with 29 additions and 1 deletions

View File

@ -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

View File

@ -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)
}
}