feat: support modify the varchar type column of postgresql database in sync function

This commit is contained in:
DacongDA 2024-02-21 19:57:01 +08:00
parent 0c9a2f6a70
commit c44e147a9f
1 changed files with 4 additions and 2 deletions

View File

@ -168,7 +168,8 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
tbNameWithSchema, col.Name, curType, expectedType) tbNameWithSchema, col.Name, curType, expectedType)
} }
} else if strings.HasPrefix(curType, schemas.Varchar) && strings.HasPrefix(expectedType, schemas.Varchar) { } 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 { if oriCol.Length < col.Length {
engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n", engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
tbNameWithSchema, col.Name, oriCol.Length, col.Length) tbNameWithSchema, col.Name, oriCol.Length, col.Length)
@ -184,7 +185,8 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
} }
} }
} else if expectedType == schemas.Varchar { } 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 { if oriCol.Length < col.Length {
engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n", engine.logger.Infof("Table %s column %s change type from varchar(%d) to varchar(%d)\n",
tbNameWithSchema, col.Name, oriCol.Length, col.Length) tbNameWithSchema, col.Name, oriCol.Length, col.Length)