diff --git a/src/node.py b/src/node.py index 7dbe4fa..be75727 100644 --- a/src/node.py +++ b/src/node.py @@ -1392,7 +1392,8 @@ def dump(self, filename=None, dbname=None, username=None, - format=DumpFormat.Plain): + format=DumpFormat.Plain, + options=None): """ Dump database into a file using pg_dump. NOTE: the file is not removed automatically. @@ -1402,6 +1403,7 @@ def dump(self, dbname: database name to connect to. username: database user name. format: format argument plain/custom/directory/tar. + options: additional options for pg_dump (list). Returns: Path to a file containing dump. @@ -1435,6 +1437,10 @@ def tmpfile(): "-F", format.value ] # yapf: disable + # Add additional options if provided + if options: + _params.extend(options) + execute_utility2(self.os_ops, _params, self.utils_log_file) return filename diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index e308a95..d292de5 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -1227,6 +1227,31 @@ def test_dump(self, node_svc: PostgresNodeService): res = node3.execute(query_select) assert (res == [(1, ), (2, )]) + def test_dump_with_options(self, node_svc: PostgresNodeService): + assert isinstance(node_svc, PostgresNodeService) + query_create = 'create table test_options as select generate_series(1, 5) as val' + + with __class__.helper__get_node(node_svc).init().start() as node1: + node1.execute(query_create) + + # Test dump with --schema-only option + with removing(node_svc.os_ops, node1.dump(options=['--schema-only'])) as dump: + with __class__.helper__get_node(node_svc).init().start() as node2: + assert (os.path.isfile(dump)) + # restore schema-only dump + node2.restore(filename=dump) + + # Check that table exists but has no data + res = node2.execute("SELECT COUNT(*) FROM test_options") + assert (res == [(0,)]) # Table exists but empty + + # Verify table structure exists + res = node2.execute(""" + SELECT COUNT(*) FROM information_schema.tables + WHERE table_name = 'test_options' + """) + assert (res == [(1,)]) # Table structure exists + def test_pgbench(self, node_svc: PostgresNodeService): assert isinstance(node_svc, PostgresNodeService)