Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Put postgres restore in a single transaction
天舟1fba38fc745c
diff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.goindex 7aa56a5f70..552637ec61 100644--- a/plugin/db/pg/pg.go+++ b/plugin/db/pg/pg.go@@ -365,6 +365,12 @@ func (driver *Driver) Dump(ctx context.Context, database string, out *os.File, s}func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err error) {+ txn, err := driver.db.BeginTx(ctx, nil)+ if err != nil {+ return err+ }+ defer txn.Rollback()+s := ""tokenName := ""for sc.Scan() {@@ -397,7 +403,7 @@ func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err error}if execute {- _, err := driver.db.Exec(s)+ _, err := txn.Exec(s)if err != nil {return fmt.Errorf("execute query %q failed: %v", s, err)}@@ -408,6 +414,10 @@ func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err errorreturn err}+ if err := txn.Commit(); err != nil {+ return err+ }+return nil}