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 <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2414
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: DacongDA <dacongda1@sina.com>
Co-committed-by: DacongDA <dacongda1@sina.com>
This commit is contained in:
DacongDA 2025-07-21 19:12:39 +00:00 committed by Lunny Xiao
parent 8f5e437a61
commit 5ed154f8c5
1 changed files with 4 additions and 2 deletions

View File

@ -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)