feat: 数据库导入执行异常错误判断忽略
This commit is contained in:
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@@ -12,6 +12,15 @@
|
||||
"program": "main.go",
|
||||
"console": "integratedTerminal",
|
||||
"args": ["--env", "local", "-c", "./local/omc.yaml"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "调试更新数据库",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"program": "main.go",
|
||||
"console": "integratedTerminal",
|
||||
"args": ["-c", "./local/omc.yaml", "--sqlPath", "./build/database/std/upgrade", "--sqlSource", "std"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func processSQLFile(db *gorm.DB, filePath string) {
|
||||
} else if strings.Contains(errorStr, "duplicate entry") {
|
||||
// 忽略重复记录错误
|
||||
// Error 1062 (23000): Duplicate entry 'value' for key 'key_name'
|
||||
log.Println(errorStr)
|
||||
log.Println(err.Error())
|
||||
} else if strings.Contains(errorStr, "unknown column") {
|
||||
// 忽略未知字段错误
|
||||
// Error 1054 (42S22): Unknown column 'field_name' in 'table'
|
||||
@@ -114,6 +114,10 @@ func processSQLFile(db *gorm.DB, filePath string) {
|
||||
// 忽略删除字段或索引错误
|
||||
// Error 1091 (42000): Can't DROP COLUMN `field_name`; check that it exists
|
||||
// Error 1091 (42000): Can't DROP 'idx_ne_type_id'; check that column/key exists
|
||||
} else if strings.Contains(errorStr, "doesn't match") {
|
||||
// 忽略列数不匹配错误
|
||||
// Error 1136 (21S01): Column count doesn't match value count at row 1
|
||||
log.Println(err.Error())
|
||||
} else {
|
||||
// 其他错误终止程序
|
||||
log.Fatalln(errorStr)
|
||||
|
||||
Reference in New Issue
Block a user