Upgrade half or gorm.
This commit is contained in:
18
code/tool/third/gorm_helper.go
Normal file
18
code/tool/third/gorm_helper.go
Normal file
@ -0,0 +1,18 @@
|
||||
package third
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
//This is a nil ptr bug in gorm.io/gorm@v1.23.2/migrator/migrator.go:369
|
||||
func MysqlMigratorHasColumn(db *gorm.DB, schemaName string, tableName string, columnName string) bool {
|
||||
|
||||
var count int64
|
||||
err := db.Raw(
|
||||
"SELECT count(*) FROM INFORMATION_SCHEMA.columns WHERE table_schema = ? AND table_name = ? AND column_name = ?",
|
||||
schemaName, tableName, columnName,
|
||||
).Row().Scan(&count)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
}
|
Reference in New Issue
Block a user