From 237572ff640de70fcf5130f17698c748608d26ce Mon Sep 17 00:00:00 2001 From: Cr <631807682@qq.com> Date: Mon, 4 Jul 2022 14:03:29 +0800 Subject: [PATCH] fix: handle database type array (#115) * fix: handle database type array * chore: code comment --- migrator.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/migrator.go b/migrator.go index 210c2cb..5eb0acc 100644 --- a/migrator.go +++ b/migrator.go @@ -478,6 +478,12 @@ func (m Migrator) ColumnTypes(value interface{}) (columnTypes []gorm.ColumnType, mc := c.(*migrator.ColumnType) if mc.NameValue.String == name { mc.ColumnTypeValue = sql.NullString{String: dataType, Valid: true} + // Handle array type: _text -> text[] , _int4 -> integer[] + // Not support array size limits and array size limits because: + // https://www.postgresql.org/docs/current/arrays.html#ARRAYS-DECLARATION + if strings.HasPrefix(mc.DataTypeValue.String, "_") { + mc.DataTypeValue = sql.NullString{String: dataType, Valid: true} + } break } }