FIX: Ensure multisite DB is set correctly when spawning backup process

FIX: Ensure multisite DB is set correctly when spawning backup process

Followup to 76477a1c8b2a51c49b8af878cf3286e9a12ae5fc

diff --git a/lib/backup_restore.rb b/lib/backup_restore.rb
index 3643cce..6528b17 100644
--- a/lib/backup_restore.rb
+++ b/lib/backup_restore.rb
@@ -174,7 +174,7 @@ module BackupRestore
     script = File.join(Rails.root, "script", "spawn_backup_restore.rb")
     command = ["bundle", "exec", "ruby", script, type, user_id, opts.to_json].shelljoin
 
-    pid = spawn(command)
+    pid = spawn({ "RAILS_DB" => RailsMultisite::ConnectionManagement.current_db }, command)
     Process.detach(pid)
   end
 

GitHub sha: fe932eb6

3 Likes

@gschlager I was struggling to find a way to rspec test this. Do you have any ideas? I guess we probably want to avoid spawning new processes while running tests.

1 Like

Thanks for fixing this! I think stubbing spawn is the only option for writing a test in this case.

1 Like