Move conditionals to separate tasks so they can be reused.

This commit is contained in:
Aaron Patterson
2011-11-16 15:01:02 -08:00
parent 272f2b778f
commit 38d26b0cb5

View File

@@ -291,15 +291,11 @@ db_namespace = namespace :db do
end
desc 'Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)'
task :setup => :environment do
db_namespace["create"].invoke
db_namespace["schema:load"].invoke if ActiveRecord::Base.schema_format == :ruby
db_namespace["structure:load"].invoke if ActiveRecord::Base.schema_format == :sql
db_namespace["seed"].invoke
end
task :setup => :seed
desc 'Load the seed data from db/seeds.rb'
task :seed => 'db:abort_if_pending_migrations' do
task :seed => ['db:schema:load_if_ruby', 'db:structure:load_if_sql'] do
db_namespace['abort_if_pending_migrations'].invoke
Rails.application.load_seed
end
@@ -362,6 +358,10 @@ db_namespace = namespace :db do
abort %{#{file} doesn't exist yet. Run `rake db:migrate` to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to limit the frameworks that will be loaded}
end
end
task :load_if_ruby => 'db:create' do
db_namespace["schema:load"].invoke if ActiveRecord::Base.schema_format == :ruby
end
end
namespace :structure do
@@ -437,6 +437,10 @@ db_namespace = namespace :db do
raise "Task not supported by '#{abcs[env]['adapter']}'"
end
end
task :load_if_sql => 'db:create' do
db_namespace["structure:load"].invoke if ActiveRecord::Base.schema_format == :sql
end
end
namespace :test do