Skip to content

Commit

Permalink
Merge pull request #12 from habx/feature/APP-19959
Browse files Browse the repository at this point in the history
APP-19959: feat(restore): support custom database schema
  • Loading branch information
habxtech authored Apr 26, 2021
2 parents 1f5bcb5 + 6a9423a commit c094abb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pg_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var (
// PGRestoreCmd is the path to the `pg_restore` executable
PGRestoreCmd = "pg_restore"
PGDRestoreStdOpts = []string{"--no-owner", "--no-acl", "--clean", "--schema=public", "--exit-on-error"}
PGDRestoreStdOpts = []string{"--no-owner", "--no-acl", "--clean", "--exit-on-error"}
)

type Restore struct {
Expand All @@ -24,10 +24,12 @@ type Restore struct {
// Extra pg_dump options
// e.g []string{"--inserts"}
Options []string
// Schemas: list of database schema
Schemas []string
}

func NewRestore(pg *Postgres) *Restore {
return &Restore{Options: PGDRestoreStdOpts, Postgres: pg}
return &Restore{Options: PGDRestoreStdOpts, Postgres: pg, Schemas: []string{"public"}}
}

// Exec `pg_restore` of the specified database, and restore from a gzip compressed tarball archive.
Expand Down Expand Up @@ -62,6 +64,10 @@ func (x *Restore) SetPath(path string) {
x.Path = path
}

func (x *Restore) SetSchemas(schemas []string) {
x.Schemas = schemas
}

func (x *Restore) restoreOptions() []string {
options := x.Options
options = append(options, x.Postgres.Parse()...)
Expand All @@ -75,5 +81,9 @@ func (x *Restore) restoreOptions() []string {
if x.Verbose {
options = append(options, "-v")
}
for _, schema := range x.Schemas {
options = append(options, "--schema=" + schema)
}

return options
}

0 comments on commit c094abb

Please sign in to comment.