@@ -3,12 +3,13 @@ package sync
33import (
44 "fmt"
55 "strings"
6+ "github.com/mohae/deepcopy"
67)
78
89func (database * Database ) ApplyDefaults (server * Server ) {
910 // set default connection if not set
1011 if database .Connection .IsEmpty () {
11- database .Connection = server .Connection
12+ database .Connection = deepcopy . Copy ( server .Connection ).( YamlCommandBuilderConnection )
1213 }
1314}
1415
@@ -43,20 +44,26 @@ func (database *Database) GetPostgres() DatabasePostgres {
4344
4445func (database * Database ) String (direction string ) string {
4546 var parts , remote , local []string
47+
48+ connRemote := database .Connection .GetInstance ()
49+ connLocal := database .Local .Connection .GetInstance ()
4650
4751 // general
4852 parts = append (parts , fmt .Sprintf ("Type:%s" , database .Type ))
4953
54+ //-------------------------------------------
5055 // remote
5156 remote = append (remote , fmt .Sprintf ("Schema:%s" , database .Schema ))
52- remote = append (remote , fmt .Sprintf ("Connection:%s" , database . Connection .GetType ()))
57+ remote = append (remote , fmt .Sprintf ("Connection:%s" , connRemote .GetType ()))
5358
54- if database .Connection .SshConnectionHostnameString () != "" {
55- remote = append (remote , fmt .Sprintf ("SSH:%s" , database .Connection .SshConnectionHostnameString ()))
59+ if connRemote .IsSsh () {
60+ if connRemote .SshConnectionHostnameString () != "" {
61+ remote = append (remote , fmt .Sprintf ("SSH:%s" , connRemote .SshConnectionHostnameString ()))
62+ }
5663 }
5764
58- if database . Connection . Docker != "" {
59- remote = append (remote , fmt .Sprintf ("Docker:%s" , database . Connection .Docker ))
65+ if connRemote . IsDocker () {
66+ remote = append (remote , fmt .Sprintf ("Docker:%s" , connRemote .Docker ))
6067 } else if database .Hostname != "" {
6168 hostname := database .Hostname
6269
@@ -74,16 +81,19 @@ func (database *Database) String(direction string) string {
7481 remote = append (remote , fmt .Sprintf ("Passwd:%s" , "*****" ))
7582 }
7683
84+ //-------------------------------------------
7785 // local
7886 local = append (local , fmt .Sprintf ("Schema:%s" , database .Local .Schema ))
79- local = append (local , fmt .Sprintf ("Connection:%s" , database . Local . Connection .GetType ()))
87+ local = append (local , fmt .Sprintf ("Connection:%s" , connLocal .GetType ()))
8088
81- if database .Local .Connection .SshConnectionHostnameString () != "" {
82- local = append (local , fmt .Sprintf ("SSH:%s" , database .Local .Connection .SshConnectionHostnameString ()))
89+ if connLocal .IsSsh () {
90+ if connLocal .SshConnectionHostnameString () != "" {
91+ local = append (local , fmt .Sprintf ("SSH:%s" , connLocal .SshConnectionHostnameString ()))
92+ }
8393 }
8494
85- if database . Local . Connection . Docker != "" {
86- local = append (local , fmt .Sprintf ("Docker:%s" , database . Local . Connection .Docker ))
95+ if connLocal . IsDocker () {
96+ local = append (local , fmt .Sprintf ("Docker:%s" , connLocal .Docker ))
8797 } else if database .Local .Hostname != "" {
8898 hostname := database .Local .Hostname
8999
0 commit comments