Script to fetch and load production dbs

This commit is contained in:
Jorge Manrubia
2025-09-23 10:49:33 +02:00
parent b2f4038ea1
commit 17e790dfc1
2 changed files with 26 additions and 2 deletions
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env ruby
require "tmpdir"
require "fileutils"
require "open3"
if ARGV.size != 1
warn "Usage: #{$PROGRAM_NAME} TENANT_ID"
exit 1
end
tenant_id = ARGV[0]
CONTAINER = "fizzy-web-production-b2f4038ea1fd054e313308940d9e445428f35b23"
REMOPTE_PATH = "/rails/storage/tenants/production/#{tenant_id}/db/main.sqlite3"
Dir.mktmpdir do |tmpdir|
local_file = File.join(tmpdir, "main.sqlite3")
puts "→ Copying #{REMOPTE_PATH} from container to #{local_file}"
cmd = %(ssh app@fizzy-app-101 "docker cp #{CONTAINER}:#{REMOPTE_PATH} -" | tar -xOf - > #{local_file})
system(cmd) or abort("Failed to copy database file")
puts "→ Running script/load-prod-db-in-dev.rb with #{local_file}"
exec("bundle", "exec", "ruby", "script/load-prod-db-in-dev.rb", local_file)
end
+2 -2
View File
@@ -33,8 +33,8 @@ FileUtils.cp original_dbfile, path, verbose: true
ActiveRecord::Tenanted::DatabaseTasks.migrate_all
ApplicationRecord.with_tenant(signup.tenant_name) do |tenant|
Account.sole.update! queenbee_id: signup.queenbee_account.id
User.first.update! signal_user_id: signup.signal_account.owner.id
Account.sole.update! external_account: signup.signal_account
User.first.update! external_user: signup.signal_account.owner
puts "\n\nLogin to http://launchpad.localhost:3011/ as #{signup.email_address} / #{signup.password}"
end