Module: Apartment::TaskHelper
- Defined in:
- lib/apartment/tasks/task_helper.rb
Class Method Summary collapse
- .create_tenant(tenant_name) ⇒ Object
- .each_tenant(&block) ⇒ Object
- .migrate_tenant(tenant_name) ⇒ Object
- .tenants ⇒ Object
- .tenants_without_default ⇒ Object
- .warn_if_tenants_empty ⇒ Object
Class Method Details
.create_tenant(tenant_name) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/apartment/tasks/task_helper.rb', line 33 def self.create_tenant(tenant_name) puts("Creating #{tenant_name} tenant") Apartment::Tenant.create(tenant_name) rescue Apartment::TenantExists => e puts "Tried to create already existing tenant: #{e}" end |
.each_tenant(&block) ⇒ Object
5 6 7 8 9 |
# File 'lib/apartment/tasks/task_helper.rb', line 5 def self.each_tenant(&block) Parallel.each(tenants_without_default, in_threads: Apartment.parallel_migration_threads) do |tenant| block.call(tenant) end end |
.migrate_tenant(tenant_name) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/apartment/tasks/task_helper.rb', line 40 def self.migrate_tenant(tenant_name) strategy = Apartment.db_migrate_tenant_missing_strategy create_tenant(tenant_name) if strategy == :create_tenant puts("Migrating #{tenant_name} tenant") Apartment::Migrator.migrate tenant_name rescue Apartment::TenantNotFound => e raise e if strategy == :raise_exception puts e. end |
.tenants ⇒ Object
15 16 17 |
# File 'lib/apartment/tasks/task_helper.rb', line 15 def self.tenants ENV['DB'] ? ENV['DB'].split(',').map(&:strip) : Apartment.tenant_names || [] end |
.tenants_without_default ⇒ Object
11 12 13 |
# File 'lib/apartment/tasks/task_helper.rb', line 11 def self.tenants_without_default tenants - [Apartment.default_tenant] end |
.warn_if_tenants_empty ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/apartment/tasks/task_helper.rb', line 19 def self.warn_if_tenants_empty return unless tenants.empty? && ENV['IGNORE_EMPTY_TENANTS'] != 'true' puts <<-WARNING [WARNING] - The list of tenants to migrate appears to be empty. This could mean a few things: 1. You may not have created any, in which case you can ignore this message 2. You've run `apartment:migrate` directly without loading the Rails environment * `apartment:migrate` is now deprecated. Tenants will automatically be migrated with `db:migrate` Note that your tenants currently haven't been migrated. You'll need to run `db:migrate` to rectify this. WARNING end |