From e1c14b69bf64f13b7daf34d2fc07ce79b0e8fe2d Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 12 Aug 2025 10:38:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=95=B0=E6=8D=AE=E5=BA=93=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=89=A7=E8=A1=8C=E5=BC=82=E5=B8=B8=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=BF=BD=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 11 ++++++++++- src/framework/database/db/expand.go | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 498a7341..a75d47af 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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"] + } ] } \ No newline at end of file diff --git a/src/framework/database/db/expand.go b/src/framework/database/db/expand.go index e17d3ddb..ec4af539 100644 --- a/src/framework/database/db/expand.go +++ b/src/framework/database/db/expand.go @@ -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)