@@ -3,12 +3,13 @@ package sync
3
3
import (
4
4
"fmt"
5
5
"strings"
6
+ "github.com/mohae/deepcopy"
6
7
)
7
8
8
9
func (database * Database ) ApplyDefaults (server * Server ) {
9
10
// set default connection if not set
10
11
if database .Connection .IsEmpty () {
11
- database .Connection = server .Connection
12
+ database .Connection = deepcopy . Copy ( server .Connection ).( YamlCommandBuilderConnection )
12
13
}
13
14
}
14
15
@@ -43,20 +44,26 @@ func (database *Database) GetPostgres() DatabasePostgres {
43
44
44
45
func (database * Database ) String (direction string ) string {
45
46
var parts , remote , local []string
47
+
48
+ connRemote := database .Connection .GetInstance ()
49
+ connLocal := database .Local .Connection .GetInstance ()
46
50
47
51
// general
48
52
parts = append (parts , fmt .Sprintf ("Type:%s" , database .Type ))
49
53
54
+ //-------------------------------------------
50
55
// remote
51
56
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 ()))
53
58
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
+ }
56
63
}
57
64
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 ))
60
67
} else if database .Hostname != "" {
61
68
hostname := database .Hostname
62
69
@@ -74,16 +81,19 @@ func (database *Database) String(direction string) string {
74
81
remote = append (remote , fmt .Sprintf ("Passwd:%s" , "*****" ))
75
82
}
76
83
84
+ //-------------------------------------------
77
85
// local
78
86
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 ()))
80
88
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
+ }
83
93
}
84
94
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 ))
87
97
} else if database .Local .Hostname != "" {
88
98
hostname := database .Local .Hostname
89
99
0 commit comments