-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f4086a
commit dcb627c
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |