Skip to content

Commit

Permalink
🐛 Quote Postgres table params to fix issues with capitalization
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Mar 23, 2022
1 parent 3502f57 commit 0d3cca8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/database/grammar/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ func (Postgres) ExecCommand(conf config.Exec) []string {
return []string{"PGPASSWORD=" + conf.Password, "psql", "--host=127.0.0.1", "--username=" + conf.Username, "--dbname=" + conf.Database}
}

func quoteParam(param string) string {
param = `"` + param + `"`
param = strings.ReplaceAll(param, "*", `"*"`)
return param
}

func (Postgres) DumpCommand(conf config.Dump) []string {
cmd := []string{"PGPASSWORD=" + conf.Password, "pg_dump", "--host=127.0.0.1", "--username=" + conf.Username, "--dbname=" + conf.Database}
if conf.Clean {
Expand All @@ -117,13 +123,13 @@ func (Postgres) DumpCommand(conf config.Dump) []string {
cmd = append(cmd, "--if-exists")
}
for _, table := range conf.Tables {
cmd = append(cmd, "--table='"+table+"'")
cmd = append(cmd, "--table='"+quoteParam(table)+"'")
}
for _, table := range conf.ExcludeTable {
cmd = append(cmd, "--exclude-table='"+table+"'")
cmd = append(cmd, "--exclude-table='"+quoteParam(table)+"'")
}
for _, table := range conf.ExcludeTableData {
cmd = append(cmd, "--exclude-table-data='"+table+"'")
cmd = append(cmd, "--exclude-table-data='"+quoteParam(table)+"'")
}
if conf.OutputFormat == sqlformat.Custom {
cmd = append(cmd, "--format=c")
Expand Down

0 comments on commit 0d3cca8

Please sign in to comment.