From 5ed154f8c55061b78ca09a88a321e052064b789e Mon Sep 17 00:00:00 2001 From: DacongDA Date: Mon, 21 Jul 2025 19:12:39 +0000 Subject: [PATCH] Feat: support modify the varchar type column of postgresql database in sync function (#2414) I'm not sure why the previous version did not support modifying the varchar length in Postgresql during sync. Perhaps it was considering compatibility issues? As nobody reply me in #2408 I decide to make a pr to solve Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/xorm/xorm/pulls/2414 Reviewed-by: Lunny Xiao Co-authored-by: DacongDA Co-committed-by: DacongDA --- sync.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sync.go b/sync.go index 5247b83d..b8b827da 100644 --- a/sync.go +++ b/sync.go @@ -171,7 +171,8 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{}) tbNameWithSchema, col.Name, curType, expectedType) } } else if strings.HasPrefix(curType, schemas.Varchar) && strings.HasPrefix(expectedType, schemas.Varchar) { - if engine.dialect.URI().DBType == schemas.MYSQL { + if engine.dialect.URI().DBType == schemas.POSTGRES || + engine.dialect.URI().DBType == schemas.MYSQL { if oriCol.Length < col.Length { engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n", tbNameWithSchema, col.Name, oriCol.Length, col.Length) @@ -187,7 +188,8 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{}) } } } else if expectedType == schemas.Varchar { - if engine.dialect.URI().DBType == schemas.MYSQL { + if engine.dialect.URI().DBType == schemas.POSTGRES || + engine.dialect.URI().DBType == schemas.MYSQL { if oriCol.Length < col.Length { engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n", tbNameWithSchema, col.Name, oriCol.Length, col.Length)