From 6b7fc81941222435b188437f6969f1417022badb Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 8 Sep 2014 11:09:42 +0800 Subject: [PATCH] add auto-migrate from varchar to text for postgres --- engine.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/engine.go b/engine.go index 3c49d947..08b17872 100644 --- a/engine.go +++ b/engine.go @@ -1191,16 +1191,19 @@ func (engine *Engine) Sync2(beans ...interface{}) error { curType := engine.dialect.SqlType(oriCol) if expectedType != curType { if expectedType == core.Text && - curType == core.Varchar { + strings.HasPrefix(curType, core.Varchar) { // currently only support mysql - if engine.dialect.DBType() == core.MYSQL { + if engine.dialect.DBType() == core.MYSQL || + engine.dialect.DBType() == core.POSTGRES { + engine.LogInfof("Table %s column %s change type from %s to %s\n", + table.Name, col.Name, curType, expectedType) _, err = engine.Exec(engine.dialect.ModifyColumnSql(table.Name, col)) } else { - engine.LogWarnf("Table %s Column %s db type is %s, struct type is %s\n", + engine.LogWarnf("Table %s column %s db type is %s, struct type is %s\n", table.Name, col.Name, curType, expectedType) } } else { - engine.LogWarnf("Table %s Column %s db type is %s, struct type is %s", + engine.LogWarnf("Table %s column %s db type is %s, struct type is %s", table.Name, col.Name, curType, expectedType) } }