Skip to content

Commit

Permalink
[70] added module
Browse files Browse the repository at this point in the history
  • Loading branch information
rpbaltazar committed Jun 25, 2020
1 parent 6f4086a commit dcb627c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/apartment/tasks/task_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Apartment
module TaskHelper
def self.each_tenant(&block)
Parallel.each(tenants_without_default, in_threads: Apartment.parallel_migration_threads) do |tenant|
block.call(tenant)
end
end

def self.tenants_without_default
tenants - [Apartment.default_schema]
end

def self.tenants
ENV['DB'] ? ENV['DB'].split(',').map(&:strip) : Apartment.tenant_names || []
end

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
end
end

0 comments on commit dcb627c

Please sign in to comment.