From f7455b02acc8d221d7467edbbfc8b6ce1a633456 Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Thu, 30 Oct 2025 16:38:39 -0700 Subject: [PATCH] Strip \restrict,\unrestrict psql meta commands from pg_dump output --- pkg/reader/postgres/pg_dump.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/reader/postgres/pg_dump.go b/pkg/reader/postgres/pg_dump.go index 7bd0a49..2f025de 100644 --- a/pkg/reader/postgres/pg_dump.go +++ b/pkg/reader/postgres/pg_dump.go @@ -3,6 +3,7 @@ package postgres import ( "bytes" "os/exec" + "strings" log "github.com/sirupsen/logrus" ) @@ -55,5 +56,16 @@ func (p *PgDump) GetStructure() (string, error) { logger.Error("failed to load schema for table") } - return buf.String(), nil + // Process the output to drop lines starting with /restrict or /unrestrict + output := buf.String() + lines := strings.Split(output, "\n") + filteredLines := make([]string, 0, len(lines)) + for _, line := range lines { + trimmed := strings.TrimSpace(line) + if !strings.HasPrefix(trimmed, `\restrict`) && !strings.HasPrefix(trimmed, `\unrestrict`) { + filteredLines = append(filteredLines, line) + } + } + + return strings.Join(filteredLines, "\n"), nil }