From 666fa4b0016318827aa9a34957ed3af2ee0585e2 Mon Sep 17 00:00:00 2001 From: ayakut Date: Wed, 20 Mar 2024 19:00:09 +0200 Subject: [PATCH 1/2] Merge pull request #1 * Fix issue with same type detection. --- migrator/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index ae82f7693..9fee9d607 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -455,7 +455,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy var ( alterColumn bool - isSameType = fullDataType == realDataType + isSameType = strings.HasPrefix(fullDataType, realDataType) ) if !field.PrimaryKey { From 980cff4d3edb859ac81274b124b33af7e2b87f05 Mon Sep 17 00:00:00 2001 From: Alex Kutko Date: Tue, 2 Apr 2024 13:15:40 +0300 Subject: [PATCH 2/2] Refactor solution to minimize regressions. --- migrator/migrator.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index 702fda2b8..b43f20f64 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -456,10 +456,10 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy var ( alterColumn bool - isSameType = strings.HasPrefix(fullDataType, realDataType) + isSameType = fullDataType == realDataType ) - if !field.PrimaryKey { + if !isSameType && !field.PrimaryKey { // check type if !strings.HasPrefix(fullDataType, realDataType) { // check type aliases @@ -474,6 +474,8 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy if !isSameType { alterColumn = true } + } else { + isSameType = true } }