-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdatabase_postgres_local.go
89 lines (65 loc) · 2.16 KB
/
database_postgres_local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package sync
import "github.com/webdevops/go-shell"
func (database *DatabasePostgres) localPgdumpCmdBuilder(additionalArgs []string, useFilter bool) []interface{} {
var args []string
connection := database.Local.Connection.GetInstance().Clone()
// add custom options (raw)
if database.Local.Options.Pgdump != nil {
args = append(args, database.Local.Options.Pgdump.Array()...)
}
if database.Local.User != "" {
args = append(args, "-U", shell.Quote(database.Local.User))
}
if database.Local.Password != "" {
connection.Environment.Set("PGPASSWORD", database.Local.Password)
}
if database.Local.Hostname != "" {
args = append(args, "-h", shell.Quote(database.Local.Hostname))
}
if database.Local.Port != "" {
args = append(args, "-p", shell.Quote(database.Local.Port))
}
if len(args) > 0 {
args = append(args, additionalArgs...)
}
// exclude
excludeArgs, includeArgs := database.tableFilter("local");
if useFilter && len(excludeArgs) > 0 {
args = append(args, excludeArgs...)
}
// database
args = append(args, shell.Quote(database.Local.Db))
// include
if useFilter && len(includeArgs) > 0 {
args = append(args, includeArgs...)
}
return connection.RawCommandBuilder("pg_dump", args...)
}
func (database *DatabasePostgres) localPsqlCmdBuilder(additonalArgs ...string) []interface{} {
var args []string
connection := database.Local.Connection.GetInstance().Clone()
// add custom options (raw)
if database.Local.Options.Psql != nil {
args = append(args, database.Local.Options.Psql.Array()...)
}
args = append(args, "-t")
if database.Local.User != "" {
args = append(args, "-U", shell.Quote(database.Local.User))
}
if database.Local.Password != "" {
connection.Environment.Set("PGPASSWORD", database.Local.Password)
}
if database.Local.Hostname != "" {
args = append(args, "-h", shell.Quote(database.Local.Hostname))
}
if database.Local.Port != "" {
args = append(args, "-p", shell.Quote(database.Local.Port))
}
if len(additonalArgs) > 0 {
args = append(args, additonalArgs...)
}
if database.Local.Db != "" {
args = append(args, shell.Quote(database.Local.Db))
}
return connection.RawCommandBuilder("psql", args...)
}