mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	启动过程中尝试自动将全部小写的表名修改为正确的表名
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user