Skip to content

Commit

Permalink
Fixed GetPgDSN behaviour
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
wwoytenko committed Feb 7, 2024
1 parent e69af71 commit 10621c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions internal/db/postgres/pgdump/pgdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (

const pgDumpExecutable = "pg_dump"

const pgDefaultPort = 5432

type PgDump struct {
BinPath string
}
Expand Down Expand Up @@ -113,14 +115,14 @@ func (o *Options) GetPgDSN() (string, error) {
if o.Host != "" {
parts = append(parts, fmt.Sprintf("host=%s", o.Host))
}
if o.Port != 5432 {
if o.Port != pgDefaultPort {
parts = append(parts, fmt.Sprintf("port=%d", o.Port))
}
if o.UserName != "" {
parts = append(parts, fmt.Sprintf("port=%d", o.Port))
parts = append(parts, fmt.Sprintf("user=%s", o.UserName))
}
if o.DbName != "" {
parts = append(parts, fmt.Sprintf("dbname=%d", o.Port))
parts = append(parts, fmt.Sprintf("dbname=%s", o.DbName))
}

return strings.Join(parts, " "), nil
Expand Down Expand Up @@ -292,7 +294,7 @@ func (o *Options) GetParams() []string {
if o.Host != "" && o.Host != "/var/run/postgres" {
args = append(args, "--host", o.Host)
}
if o.Port != 5432 {
if o.Port != pgDefaultPort {
args = append(args, "--port", strconv.FormatInt(int64(o.Port), 10))
}
if o.UserName != "" {
Expand Down
10 changes: 6 additions & 4 deletions internal/db/postgres/pgrestore/pgrestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (

const pgRestoreExecutable = "pg_restore"

const pgDefaultPort = 5432

type PgRestore struct {
BinPath string
}
Expand Down Expand Up @@ -106,14 +108,14 @@ func (o *Options) GetPgDSN() (string, error) {
if o.Host != "" {
parts = append(parts, fmt.Sprintf("host=%s", o.Host))
}
if o.Port != 5432 {
if o.Port != pgDefaultPort {
parts = append(parts, fmt.Sprintf("port=%d", o.Port))
}
if o.UserName != "" {
parts = append(parts, fmt.Sprintf("port=%d", o.Port))
parts = append(parts, fmt.Sprintf("user=%s", o.UserName))
}
if o.DbName != "" {
parts = append(parts, fmt.Sprintf("dbname=%d", o.Port))
parts = append(parts, fmt.Sprintf("dbname=%s", o.DbName))
}
return strings.Join(parts, " "), nil
}
Expand Down Expand Up @@ -253,7 +255,7 @@ func (o *Options) GetParams() []string {
if o.Host != "" && o.Host != "/var/run/postgres" {
args = append(args, "--host", o.Host)
}
if o.Port != 5432 {
if o.Port != pgDefaultPort {
args = append(args, "--port", strconv.FormatInt(int64(o.Port), 10))
}
if o.UserName != "" {
Expand Down

0 comments on commit 10621c6

Please sign in to comment.