Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added pg_dump options validation in dump command #105

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions internal/db/postgres/cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ func (d *Dump) buildContextAndValidate(ctx context.Context, tx pgx.Tx) (err erro
}

func (d *Dump) schemaOnlyDump(ctx context.Context, tx pgx.Tx) error {
if d.pgDumpOptions.DataOnly ||
(d.pgDumpOptions.Section != "" &&
d.pgDumpOptions.Section != preDataSection &&
d.pgDumpOptions.Section != postDataSection) {
return nil
}

// Dump schema
options := *d.pgDumpOptions
options.Format = "d"
Expand Down Expand Up @@ -219,6 +226,17 @@ func (d *Dump) schemaOnlyDump(ctx context.Context, tx pgx.Tx) error {
}

func (d *Dump) dataDump(ctx context.Context) error {
if d.pgDumpOptions.SchemaOnly ||
(d.pgDumpOptions.Section != "" && d.pgDumpOptions.Section != dataSection) {
return nil
}

// Since dumpIdSequence initialized in schemaOnlyDump, we need to check if it is nil
// if nil, we need to initialize it with 1
if d.dumpIdSequence == nil {
d.dumpIdSequence = toc.NewDumpSequence(1)
}

// TODO: You should use pointer to dumpers.DumpTask instead
tasks := make(chan dumpers.DumpTask, d.pgDumpOptions.Jobs)
result := make(chan entries.Entry, d.pgDumpOptions.Jobs)
Expand Down