Skip to content

Commit

Permalink
feat(pg_dump): Add '--if-exists' option for pg_dump (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroLitvinov committed Mar 5, 2024
1 parent 9208919 commit 6598429
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dbbackup/db/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class PgDumpBinaryConnector(PgDumpConnector):
restore_cmd = "pg_restore"
single_transaction = True
drop = True
if_exists = False

def _create_dump(self):
cmd = f"{self.dump_cmd} "
Expand All @@ -120,6 +121,8 @@ def _restore_dump(self, dump):
cmd += " --single-transaction"
if self.drop:
cmd += " --clean"
if self.if_exists:
cmd += " --if-exists"

Check warning on line 125 in dbbackup/db/postgresql.py

View check run for this annotation

Codecov / codecov/patch

dbbackup/db/postgresql.py#L125

Added line #L125 was not covered by tests
cmd = f"{self.restore_prefix} {cmd} {self.restore_suffix}"
stdout, stderr = self.run_command(cmd, stdin=dump, env=self.restore_env)
return stdout, stderr
7 changes: 7 additions & 0 deletions docs/databases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ This corresponds to ``--clean`` argument of ``pg_dump`` and ``pg_restore``.

Default: ``True``

IF_EXISTS
~~~~

Use DROP ... IF EXISTS commands to drop objects in ``--clean`` mode of ``pg_dump``.

Default: ``False``

PostGIS
-------

Expand Down

0 comments on commit 6598429

Please sign in to comment.