Skip to content

Commit

Permalink
add migrate_tenant task helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jonian authored and rpbaltazar committed Jan 21, 2021
1 parent 50ebd85 commit 8ab8bbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 12 additions & 0 deletions lib/apartment/tasks/task_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,17 @@ def self.create_tenant(tenant_name)
rescue Apartment::TenantExists => e
puts "Tried to create already existing tenant: #{e}"
end

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.message
end
end
end
8 changes: 1 addition & 7 deletions lib/tasks/apartment.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ apartment_namespace = namespace :apartment do
task :migrate do
Apartment::TaskHelper.warn_if_tenants_empty
Apartment::TaskHelper.each_tenant do |tenant|
begin
Apartment::TaskHelper.create_tenant(tenant)
puts("Migrating #{tenant} tenant")
Apartment::Migrator.migrate tenant
rescue Apartment::TenantNotFound => e
puts e.message
end
Apartment::TaskHelper.migrate_tenant(tenant)
end
end

Expand Down

0 comments on commit 8ab8bbd

Please sign in to comment.