fix: 忽略特定SQL执行错误
This commit is contained in:
@@ -93,11 +93,17 @@ func processSQLFile(db *gorm.DB, filePath string) {
|
|||||||
if strings.HasSuffix(line, ";") {
|
if strings.HasSuffix(line, ";") {
|
||||||
// 执行 SQL 语句
|
// 执行 SQL 语句
|
||||||
if err := db.Exec(sqlBuilder.String()).Error; err != nil {
|
if err := db.Exec(sqlBuilder.String()).Error; err != nil {
|
||||||
errorStr := err.Error()
|
errorStr := strings.ToLower(err.Error())
|
||||||
if strings.Contains(strings.ToLower(errorStr), "duplicate column") {
|
// log.Printf("Exec SQL: %s\n", line)
|
||||||
// 重复字段错误忽略
|
// log.Println(err.Error())
|
||||||
// log.Printf("Exec SQL: %s\n", line)
|
if strings.Contains(errorStr, "duplicate column") {
|
||||||
// log.Println(err.Error())
|
// 忽略重复字段错误 Error 1060 (42S21): Duplicate column name 'field_name'
|
||||||
|
} else if strings.Contains(errorStr, "duplicate key") {
|
||||||
|
// 忽略重复索引错误 Error 1061 (42000): Duplicate key name 'key_name'
|
||||||
|
} else if strings.Contains(errorStr, "unknown column") {
|
||||||
|
// 忽略未知字段错误 Error 1054 (42S22): Unknown column 'field_name' in 'table'
|
||||||
|
} else if strings.Contains(errorStr, "check that it exists") {
|
||||||
|
// 忽略删除字段错误 Error 1091 (42000): Can't DROP COLUMN `field_name`; check that it exists
|
||||||
} else {
|
} else {
|
||||||
// 其他错误终止程序
|
// 其他错误终止程序
|
||||||
log.Fatalln(errorStr)
|
log.Fatalln(errorStr)
|
||||||
|
|||||||
Reference in New Issue
Block a user