From 9ff03757603ec4f76c24f5b14df9112c24e21231 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 8 May 2024 15:29:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E8=BF=87=E7=A8=8B=E4=B8=AD?= =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=87=AA=E5=8A=A8=E5=B0=86=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E5=B0=8F=E5=86=99=E7=9A=84=E8=A1=A8=E5=90=8D=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E6=AD=A3=E7=A1=AE=E7=9A=84=E8=A1=A8=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/api_node.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/nodes/api_node.go b/internal/nodes/api_node.go index 217b5001..56163bd4 100644 --- a/internal/nodes/api_node.go +++ b/internal/nodes/api_node.go @@ -137,6 +137,7 @@ func (this *APINode) Start() { // 数据库通知启动 this.setProgress("DATABASE", "正在建立数据库模型") logs.Println("[API_NODE]notify ready ...") + this.processTableNames() dbs.NotifyReady() // 设置时区 @@ -467,6 +468,35 @@ func (this *APINode) setupDB() error { return nil } +// 处理表名兼容 +func (this *APINode) processTableNames() { + dbs.OnDAOInitError(func(dao dbs.DAOInterface, err error) error { + if err == nil { + return nil + } + + if errors.Is(err, dbs.ErrTableNotFound) { + var instance = dao.Object().Instance + if instance == nil { + return err + } + + // 查找完全小写的 + var lowerTableName = strings.ToLower(dao.Object().Table) + lowerTable, _ := instance.FindTable(lowerTableName) + if lowerTable != nil { + _, err = instance.Exec("RENAME TABLE `" + lowerTableName + "` TO `" + dao.Object().Table + "`") + if err == nil { + logs.Println("[API_NODE]rename table '" + lowerTableName + "' to '" + dao.Object().Table + "'") + return dao.Object().Init() + } + } + } + + return err + }) +} + // 启动端口 func (this *APINode) listenPorts(apiNode *models.APINode) (isListening bool) { // HTTP