From c3253a5c59b078607db9e216ddc11afdef546e05 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Sun, 20 Oct 2024 11:17:46 +0200 Subject: [PATCH] fix: ignore case for type equivalence --- dialect/pgdialect/sqltype.go | 6 +++--- dialect/pgdialect/sqltype_test.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dialect/pgdialect/sqltype.go b/dialect/pgdialect/sqltype.go index a595df5be..ce7f9c8b5 100644 --- a/dialect/pgdialect/sqltype.go +++ b/dialect/pgdialect/sqltype.go @@ -126,12 +126,12 @@ var ( ) func (d *Dialect) EquivalentType(col1, col2 sqlschema.Column) bool { - if col1.SQLType == col2.SQLType { + typ1, typ2 := strings.ToUpper(col1.SQLType), strings.ToUpper(col2.SQLType) + + if typ1 == typ2 { return checkVarcharLen(col1, col2, d.DefaultVarcharLen()) } - typ1, typ2 := strings.ToUpper(col1.SQLType), strings.ToUpper(col2.SQLType) - switch { case char.IsAlias(typ1) && char.IsAlias(typ2): return checkVarcharLen(col1, col2, d.DefaultVarcharLen()) diff --git a/dialect/pgdialect/sqltype_test.go b/dialect/pgdialect/sqltype_test.go index 5a51e1275..77cf1e153 100644 --- a/dialect/pgdialect/sqltype_test.go +++ b/dialect/pgdialect/sqltype_test.go @@ -16,7 +16,8 @@ func TestInspectorDialect_EquivalentType(t *testing.T) { typ1, typ2 string want bool }{ - {"text", "text", true}, // identical types + {"text", "text", true}, // identical types + {"bigint", "BIGINT", true}, // case-insensitive {sqltype.VarChar, pgTypeVarchar, true}, {sqltype.VarChar, pgTypeCharacterVarying, true},