mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 18:10:25 +08:00
保持导出SQL的稳定性
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@@ -67,7 +68,11 @@ func (this *SQLDump) Dump(db *dbs.DB, includingRecords bool) (result *SQLDumpRes
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for tableName, table := range fullTableMap {
|
var autoIncrementReg = regexp.MustCompile(` AUTO_INCREMENT=\d+`)
|
||||||
|
|
||||||
|
for _, table := range fullTableMap {
|
||||||
|
var tableName = table.Name
|
||||||
|
|
||||||
// 忽略一些分表
|
// 忽略一些分表
|
||||||
if strings.HasPrefix(strings.ToLower(tableName), strings.ToLower("edgeHTTPAccessLogs_")) {
|
if strings.HasPrefix(strings.ToLower(tableName), strings.ToLower("edgeHTTPAccessLogs_")) {
|
||||||
continue
|
continue
|
||||||
@@ -76,11 +81,11 @@ func (this *SQLDump) Dump(db *dbs.DB, includingRecords bool) (result *SQLDumpRes
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlTable := &SQLTable{
|
var sqlTable = &SQLTable{
|
||||||
Name: table.Name,
|
Name: table.Name,
|
||||||
Engine: table.Engine,
|
Engine: table.Engine,
|
||||||
Charset: table.Collation,
|
Charset: table.Collation,
|
||||||
Definition: regexp.MustCompile(` AUTO_INCREMENT=\d+`).ReplaceAllString(table.Code, ""),
|
Definition: autoIncrementReg.ReplaceAllString(table.Code, ""),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 字段
|
// 字段
|
||||||
@@ -424,10 +429,10 @@ func (this *SQLDump) applyQueue(db *dbs.DB, newResult *SQLDumpResult, showLog bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 查找所有表的完整信息
|
// 查找所有表的完整信息
|
||||||
func (this *SQLDump) findFullTables(db *dbs.DB, tableNames []string) (map[string]*dbs.Table, error) {
|
func (this *SQLDump) findFullTables(db *dbs.DB, tableNames []string) ([]*dbs.Table, error) {
|
||||||
var fullTableMap = map[string]*dbs.Table{}
|
var fullTables = []*dbs.Table{}
|
||||||
if len(tableNames) == 0 {
|
if len(tableNames) == 0 {
|
||||||
return fullTableMap, nil
|
return fullTables, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var locker = &sync.Mutex{}
|
var locker = &sync.Mutex{}
|
||||||
@@ -460,7 +465,8 @@ func (this *SQLDump) findFullTables(db *dbs.DB, tableNames []string) (map[string
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
fullTableMap[tableName] = table
|
table.Name = tableName
|
||||||
|
fullTables = append(fullTables, table)
|
||||||
locker.Unlock()
|
locker.Unlock()
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
@@ -473,7 +479,12 @@ func (this *SQLDump) findFullTables(db *dbs.DB, tableNames []string) (map[string
|
|||||||
return nil, lastErr
|
return nil, lastErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return fullTableMap, nil
|
// 排序
|
||||||
|
sort.Slice(fullTables, func(i, j int) bool {
|
||||||
|
return fullTables[i].Name < fullTables[j].Name
|
||||||
|
})
|
||||||
|
|
||||||
|
return fullTables, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找有记录的表
|
// 查找有记录的表
|
||||||
|
|||||||
Reference in New Issue
Block a user