Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: pg dump skip comment and extra empty line (#1542)
Danny Xuf50e0122903c
diff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.goindex a654720339..86c26e51ac 100644--- a/plugin/db/pg/pg.go+++ b/plugin/db/pg/pg.go@@ -986,16 +986,33 @@ func (driver *Driver) dumpOneDatabaseWithPgDump(ctx context.Context, database streturn err}s := bufio.NewScanner(r)+ previousLineComment := false+ previousLineEmpty := falsefor s.Scan() {line := s.Text()// Skip "SET SESSION AUTHORIZATION" till we can support it.if strings.HasPrefix(line, "SET SESSION AUTHORIZATION ") {continue}- // Skip dump client and server version header.- if strings.HasPrefix(line, "-- Dumped from database version") || strings.HasPrefix(line, "-- Dumped by pg_dump version") {+ // Skip comment lines.+ if strings.HasPrefix(line, "--") {+ previousLineComment = truecontinue}+ if previousLineComment && line == "" {+ previousLineComment = false+ continue+ }+ previousLineComment = false+ // Skip extra empty lines.+ if line == "" {+ if previousLineEmpty {+ continue+ }+ previousLineEmpty = true+ } else {+ previousLineEmpty = false+ }if _, err := io.WriteString(out, line); err != nil {return err