Created
August 15, 2013 21:12
-
-
Save mattscilipoti/6244953 to your computer and use it in GitHub Desktop.
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
db_tasks = %w[db:migrate db:migrate:up db:migrate:down db:rollback db:seed db:version] # db:forward] | |
namespace :multitenant do | |
desc 'List all existing tenants/customers' | |
task :list => :environment do | |
puts Customer.all.collect &:name | |
end | |
#create a multitenant task for each db task | |
db_tasks.each do |task_name| | |
desc "Run #{task_name} for each tenant/customer" | |
task task_name => %w[environment db:load_config] do | |
Customer.find_each do |tenant| | |
puts "Running #{task_name} for tenant#{tenant.id} (#{tenant.subdomain})" | |
tenant.use { Rake::Task[task_name].execute } | |
end | |
end | |
end | |
end | |
# Update db tasks, running the task for each tenant, after running for public | |
db_tasks.each do |task_name| | |
task task_name do | |
multitenant_task = "multitenant:#{task_name}" | |
Rake::Task[multitenant_task].invoke | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment