From 25a2619d84355fb7de51c92dedd245ea38ce72f6 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 13 Mar 2023 10:36:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=90=9C=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E6=93=8EIP=E5=BA=93=E5=8F=AF=E8=83=BD=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/setup/sql_dump.go | 19 ++++++++++++++++--- internal/setup/sql_records_table.go | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/setup/sql_dump.go b/internal/setup/sql_dump.go index 1bf1627a..f58ddb9e 100644 --- a/internal/setup/sql_dump.go +++ b/internal/setup/sql_dump.go @@ -6,6 +6,7 @@ import ( "github.com/go-sql-driver/mysql" "github.com/iwind/TeaGo/dbs" "github.com/iwind/TeaGo/lists" + "github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/types" "io" "regexp" @@ -57,6 +58,7 @@ var recordsTables = []*SQLRecordsTable{ { TableName: "edgeClientAgentIPs", UniqueFields: []string{"agentId", "ip"}, + IgnoreId: true, }, } @@ -374,6 +376,7 @@ func (this *SQLDump) applyQueue(db *dbs.DB, newResult *SQLDumpResult, showLog bo // 对比记录 // + + var newRecordsTable = this.findRecordsTable(newTable.Name) for _, record := range newTable.Records { var queryArgs = []string{} var queryValues = []any{} @@ -392,8 +395,15 @@ func (this *SQLDump) applyQueue(db *dbs.DB, newResult *SQLDumpResult, showLog bo } } - queryValues = append(queryValues, recordId) - one, err := db.FindOne("SELECT * FROM "+newTable.Name+" WHERE (("+strings.Join(queryArgs, " AND ")+") OR id=?)", queryValues...) + var one maps.Map + + if newRecordsTable != nil && newRecordsTable.IgnoreId { + one, err = db.FindOne("SELECT * FROM "+newTable.Name+" WHERE (("+strings.Join(queryArgs, " AND ")+"))", queryValues...) + } else { + queryValues = append(queryValues, recordId) + one, err = db.FindOne("SELECT * FROM "+newTable.Name+" WHERE (("+strings.Join(queryArgs, " AND ")+") OR id=?)", queryValues...) + } + if err != nil { return nil, err } @@ -411,7 +421,10 @@ func (this *SQLDump) applyQueue(db *dbs.DB, newResult *SQLDumpResult, showLog bo continue } - // ID需要保留,因为各个表格之间需要有对应关系 + if newRecordsTable != nil && newRecordsTable.IgnoreId && k == "id" { + continue + } + params = append(params, "`"+k+"`") args = append(args, "?") values = append(values, v) diff --git a/internal/setup/sql_records_table.go b/internal/setup/sql_records_table.go index 5ca836ab..61f9f7af 100644 --- a/internal/setup/sql_records_table.go +++ b/internal/setup/sql_records_table.go @@ -4,4 +4,5 @@ type SQLRecordsTable struct { TableName string UniqueFields []string ExceptFields []string + IgnoreId bool // 是否可以排除ID }