From 99fc5664a8d277a07a909b6f02024d1de2dd03ff Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 18 Jul 2025 10:13:23 -0400 Subject: [PATCH] Script to load prod db in development --- script/load-prod-db-in-dev.rb | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 script/load-prod-db-in-dev.rb diff --git a/script/load-prod-db-in-dev.rb b/script/load-prod-db-in-dev.rb new file mode 100755 index 000000000..8585a2bba --- /dev/null +++ b/script/load-prod-db-in-dev.rb @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby + +if ARGV.length != 1 + puts "Usage: #{$0} " + exit 1 +end +original_dbfile = ARGV[0] + +require_relative "../config/environment" + +unless Rails.env.local? + abort "This script should only be run in a local development environment." +end + +identifier = SecureRandom.hex(4) +signup = Signup.new( + email_address: "dev-#{identifier}@example.com", + full_name: "Developer #{identifier}", + company_name: "Company #{identifier}", + password: "secret123456" +) + +puts "Creating signal identity for #{signup.email_address}..." +signup.send(:create_signal_identity) + +puts "Creating queenbee account ..." +signup.send(:create_queenbee_account) + +path = ApplicationRecord.tenanted_root_config.database_path_for(signup.tenant_name) +FileUtils.mkdir_p(File.dirname(path), verbose: true) +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 + + puts "\n\nLogin to http://launchpad.localhost:3011/ as #{signup.email_address} / #{signup.password}" +end