Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resolves #86] error running db seed task #87

Merged
merged 2 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/apartment/tasks/task_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ def self.warn_if_tenants_empty
Note that your tenants currently haven't been migrated. You'll need to run `db:migrate` to rectify this.
WARNING
end

def self.create_tenant(tenant_name)
Apartment::Tenant.create(tenant_name)
rescue Apartment::TenantExists => e
puts "Tried to create already existing tenant: #{e}"
end
end
end
11 changes: 4 additions & 7 deletions lib/tasks/apartment.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ apartment_namespace = namespace :apartment do
Apartment::TaskHelper.warn_if_tenants_empty

Apartment::TaskHelper.tenants.each do |tenant|
begin
puts("Creating #{tenant} tenant")
Apartment::Tenant.create(tenant)
rescue Apartment::TenantExists => e
puts e.message
end
Apartment::TaskHelper.create_tenant(tenant)
end
end

Expand All @@ -36,6 +31,7 @@ apartment_namespace = namespace :apartment 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
Expand All @@ -45,11 +41,12 @@ apartment_namespace = namespace :apartment do
end

desc 'Seed all tenants'
task seed: :create do
task :seed do
Apartment::TaskHelper.warn_if_tenants_empty

Apartment::TaskHelper.each_tenant do |tenant|
begin
Apartment::TaskHelper.create_tenant(tenant)
puts("Seeding #{tenant} tenant")
Apartment::Tenant.switch(tenant) do
Apartment::Tenant.seed
Expand Down