From 366563a0fee51e28b7abbfe0c332aa68ec579786 Mon Sep 17 00:00:00 2001 From: "meilin.huang" <954537473@qq.com> Date: Sun, 24 Jul 2022 18:54:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20sql=E6=96=87=E4=BB=B6=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=90=8D=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/internal/devops/application/db_app.go | 3 +-- .../devops/infrastructure/machine/sshtunnel.go | 2 +- server/mayfly-go.sql | 16 ++++++++-------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/server/internal/devops/application/db_app.go b/server/internal/devops/application/db_app.go index 4c6325c5..a554a6a2 100644 --- a/server/internal/devops/application/db_app.go +++ b/server/internal/devops/application/db_app.go @@ -258,10 +258,9 @@ func GetDbConn(d *entity.Db, db string) (*sql.DB, error) { // SSH Conect if d.EnableSshTunnel == 1 && d.SshTunnelMachineId != 0 { sshTunnelMachine := MachineApp.GetSshTunnelMachine(d.SshTunnelMachineId) - defer machine.CloseSshTunnelMachine(d.SshTunnelMachineId, 0) if d.Type == entity.DbTypeMysql { mysql.RegisterDialContext(d.Network, func(ctx context.Context, addr string) (net.Conn, error) { - return MachineApp.GetSshTunnelMachine(d.SshTunnelMachineId).GetDialConn("tcp", addr) + return sshTunnelMachine.GetDialConn("tcp", addr) }) } else if d.Type == entity.DbTypePostgres { _, err := pq.DialOpen(&PqSqlDialer{sshTunnelMachine: sshTunnelMachine}, getDsn(d, db)) diff --git a/server/internal/devops/infrastructure/machine/sshtunnel.go b/server/internal/devops/infrastructure/machine/sshtunnel.go index 4f8f56b7..f4843dda 100644 --- a/server/internal/devops/infrastructure/machine/sshtunnel.go +++ b/server/internal/devops/infrastructure/machine/sshtunnel.go @@ -130,7 +130,7 @@ func (stm *SshTunnelMachine) Close() { global.Log.Infof("ssh隧道机器[%d]未被使用, 关闭隧道...", stm.machineId) err := stm.SshClient.Close() if err != nil { - global.Log.Errorf("关闭ssh隧道机器[%s]发生错误: %s", stm.machineId, err.Error()) + global.Log.Errorf("关闭ssh隧道机器[%d]发生错误: %s", stm.machineId, err.Error()) } } delete(sshTunnelMachines, stm.machineId) diff --git a/server/mayfly-go.sql b/server/mayfly-go.sql index 6b347dd2..f82474c1 100644 --- a/server/mayfly-go.sql +++ b/server/mayfly-go.sql @@ -30,8 +30,8 @@ CREATE TABLE `t_db` ( `database` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '数据库,空格分割多个数据库', `params` varchar(125) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '其他连接参数', `network` varchar(20) COLLATE utf8mb4_bin DEFAULT NULL, - `enableSshTunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道', - `sshTunnelMachineId` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id', + `enable_ssh_tunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道', + `ssh_tunnel_machine_id` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id', `project_id` bigint(20) DEFAULT NULL, `project` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL, `env_id` bigint(20) DEFAULT NULL COMMENT '环境id', @@ -111,8 +111,8 @@ CREATE TABLE `t_machine` ( `username` varchar(12) COLLATE utf8mb4_bin NOT NULL, `auth_method` tinyint(2) NULL DEFAULT NULL COMMENT '1.密码登录2.publickey登录', `password` varchar(3200) COLLATE utf8mb4_bin DEFAULT NULL, - `enableSshTunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道', - `sshTunnelMachineId` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id', + `enable_ssh_tunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道', + `ssh_tunnel_machine_id` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id', `status` tinyint(2) NOT NULL COMMENT '状态: 1:启用; -1:禁用', `remark` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL, `need_monitor` tinyint(2) DEFAULT NULL, @@ -263,8 +263,8 @@ CREATE TABLE `t_redis` ( `password` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL, `db` int(32) DEFAULT NULL, `mode` varchar(32) DEFAULT NULL, - `enableSshTunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道', - `sshTunnelMachineId` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id', + `enable_ssh_tunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道', + `ssh_tunnel_machine_id` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id', `remark` varchar(125) DEFAULT NULL, `project_id` bigint(20) DEFAULT NULL, `project` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL, @@ -670,8 +670,8 @@ CREATE TABLE `t_mongo` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(36) COLLATE utf8mb4_bin NOT NULL COMMENT '名称', `uri` varchar(255) COLLATE utf8mb4_bin NOT NULL COMMENT '连接uri', - `enableSshTunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道', - `sshTunnelMachineId` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id', + `enable_ssh_tunnel` tinyint(2) DEFAULT NULL COMMENT '是否启用ssh隧道', + `ssh_tunnel_machine_id` bigint(20) DEFAULT NULL COMMENT 'ssh隧道的机器id', `project_id` bigint(20) NOT NULL, `project` varchar(36) COLLATE utf8mb4_bin DEFAULT NULL, `env_id` bigint(20) DEFAULT NULL,