Merge pull request #764 from basecamp/flavorjones/load-prod-db-in-dev
Script to load a production db in development
This commit is contained in:
@@ -55,7 +55,7 @@ class Signup
|
||||
end
|
||||
|
||||
def tenant_name
|
||||
@tenant_name ||= signal_account.subdomain
|
||||
@tenant_name ||= @queenbee_account.id.to_s
|
||||
end
|
||||
|
||||
def to_h
|
||||
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
if ARGV.length != 1
|
||||
puts "Usage: #{$0} <dbfile>"
|
||||
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
|
||||
@@ -66,7 +66,7 @@ class Signup::AccountsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
signal_account = SignalId::Account.last
|
||||
ApplicationRecord.with_tenant(signal_account.subdomain) do
|
||||
ApplicationRecord.with_tenant(signal_account.queenbee_id) do
|
||||
assert_equal Account.last, signal_account.peer
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,7 +44,8 @@ class SignupTest < ActiveSupport::TestCase
|
||||
assert @signup.user.persisted?
|
||||
assert_equal @signup.user.signal_user, @signup.signal_account.owner
|
||||
|
||||
assert_includes ApplicationRecord.tenants, @signup.signal_account.subdomain
|
||||
assert_equal @signup.queenbee_account.id.to_s, @signup.tenant_name
|
||||
assert_includes ApplicationRecord.tenants, @signup.tenant_name
|
||||
end
|
||||
|
||||
test "the new account is named with company name if present" do
|
||||
@@ -87,7 +88,8 @@ class SignupTest < ActiveSupport::TestCase
|
||||
assert @signup.user.persisted?
|
||||
assert_equal @signup.user.signal_user, @signup.signal_account.owner
|
||||
|
||||
assert_includes ApplicationRecord.tenants, @signup.signal_account.subdomain
|
||||
assert_equal @signup.queenbee_account.id.to_s, @signup.tenant_name
|
||||
assert_includes ApplicationRecord.tenants, @signup.tenant_name
|
||||
end
|
||||
|
||||
test "#process does nothing if a validation error occurs creating identity" do
|
||||
|
||||
Reference in New Issue
Block a user