From 0eaff331688bcb369897205f67e3263461bb9524 Mon Sep 17 00:00:00 2001 From: wanli Date: Tue, 5 Sep 2023 14:15:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=B1=E4=BA=8E=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20PostgreSQL=EF=BC=8C=E9=9D=9E=20MySQL=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E9=99=90=E5=88=B6=E4=BD=BF=E7=94=A8=E8=AF=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/internal/db/api/db.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/server/internal/db/api/db.go b/server/internal/db/api/db.go index a8af29d6..4c3846b4 100644 --- a/server/internal/db/api/db.go +++ b/server/internal/db/api/db.go @@ -271,31 +271,37 @@ func (d *Db) DumpSql(rc *req.Ctx) { if len(dbNames) == 1 && len(tablesStr) > 0 { tables = strings.Split(tablesStr, ",") } + + instance := d.InstanceApp.GetById(db.InstanceId) writer := gzipResponseWriter{writer: gzip.NewWriter(g.Writer)} defer writer.Close() for _, dbName := range dbNames { - d.dumpDb(writer, db, dbName, tables, needStruct, needData) + d.dumpHeader(writer, instance, dbName, len(dbNames) > 1) + d.dumpDb(writer, db, instance, dbName, tables, needStruct, needData) } rc.ReqParam = fmt.Sprintf("DB[id=%d, tag=%s, name=%s, databases=%s, tables=%s, dumpType=%s]", db.Id, db.TagPath, db.Name, dbNamesStr, tablesStr, dumpType) } -func (d *Db) dumpDb(writer gzipResponseWriter, db *entity.Db, dbName string, tables []string, needStruct bool, needData bool) { +func (d *Db) dumpHeader(writer gzipResponseWriter, instance *entity.Instance, dbName string, switchDb bool) { writer.WriteString("-- ----------------------------") writer.WriteString("\n-- 导出平台: mayfly-go") writer.WriteString(fmt.Sprintf("\n-- 导出时间: %s ", time.Now().Format("2006-01-02 15:04:05"))) writer.WriteString(fmt.Sprintf("\n-- 导出数据库: %s ", dbName)) writer.WriteString("\n-- ----------------------------\n") - instance := d.InstanceApp.GetById(db.InstanceId) - dbInst := d.DbApp.GetDbConnection(db, instance, dbName) - - switch dbInst.Info.Type { - case entity.DbTypeMysql: - writer.WriteString(fmt.Sprintf("use `%s`;\n", dbName)) - default: - biz.IsTrue(false, "数据库类型必须为 %s", entity.DbTypeMysql) + if switchDb { + switch instance.Type { + case entity.DbTypeMysql: + writer.WriteString(fmt.Sprintf("use `%s`;\n", dbName)) + default: + biz.IsTrue(false, "数据库类型必须为 %s", entity.DbTypeMysql) + } } +} + +func (d *Db) dumpDb(writer gzipResponseWriter, db *entity.Db, instance *entity.Instance, dbName string, tables []string, needStruct bool, needData bool) { + dbInst := d.DbApp.GetDbConnection(db, instance, dbName) dbMeta := dbInst.GetMeta() if len(tables) == 0 { ti := dbMeta.GetTableInfos()