@@ -113,6 +113,7 @@ class PgDumpBinaryConnector(PgDumpConnector):
113113 single_transaction = True
114114 drop = True
115115 if_exists = False
116+ pg_options = None
116117
117118 def _create_dump (self ):
118119 cmd = f"{ self .dump_cmd } "
@@ -129,22 +130,64 @@ def _create_dump(self):
129130 stdout , _ = self .run_command (cmd , env = self .dump_env )
130131 return stdout
131132
132- def _restore_dump (self , dump ):
133+ def _restore_dump (self , dump : str ):
134+ """
135+ Restore a PostgreSQL dump using subprocess with argument list.
136+
137+ Assumes that restore_prefix, restore_cmd, pg_options, and restore_suffix
138+ are either None, strings (single args), or lists of strings.
139+
140+ Builds the command as a list.
141+ """
142+
133143 dbname = create_postgres_uri (self )
134- cmd = f"{ self .restore_cmd } { dbname } "
144+ cmd = []
145+
146+ # Flatten optional values
147+ if self .restore_prefix :
148+ cmd .extend (
149+ self .restore_prefix
150+ if isinstance (self .restore_prefix , list )
151+ else [self .restore_prefix ]
152+ )
153+
154+ if self .restore_cmd :
155+ cmd .extend (
156+ self .restore_cmd
157+ if isinstance (self .restore_cmd , list )
158+ else [self .restore_cmd ]
159+ )
160+
161+ if self .pg_options :
162+ cmd .extend (
163+ self .pg_options
164+ if isinstance (self .pg_options , list )
165+ else [self .pg_options ]
166+ )
167+
168+ cmd .extend ([dbname ])
135169
136170 if self .single_transaction :
137- cmd += " --single-transaction"
171+ cmd . extend ([ " --single-transaction"])
138172
139173 if self .drop :
140- cmd += " --clean"
174+ cmd . extend ([ " --clean"])
141175
142176 if self .schemas :
143- cmd += " -n " + " -n " .join (self .schemas )
177+ for schema in self .schemas :
178+ cmd .extend (["-n" , schema ])
144179
145180 if self .if_exists :
146- cmd += " --if-exists"
181+ cmd . extend ([ " --if-exists"])
147182
148- cmd = f"{ self .restore_prefix } { cmd } { self .restore_suffix } "
149- stdout , stderr = self .run_command (cmd , stdin = dump , env = self .restore_env )
150- return stdout , stderr
183+ if self .restore_suffix :
184+ cmd .extend (
185+ self .restore_suffix
186+ if isinstance (self .restore_suffix , list )
187+ else [self .restore_suffix ]
188+ )
189+
190+ cmd_str = " " .join (cmd )
191+ stdout , _ = self .run_command (cmd_str , stdin = dump , env = self .dump_env )
192+
193+ return stdout
0 commit comments