aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-11-16 15:01:02 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-11-16 15:31:37 -0800
commit38d26b0cb56d82093889efa95992a35ba3bb9f29 (patch)
treecb8e07a1133d30b97d9ed0c7f31c7b6b04378fa5
parent272f2b778fb0afeb2b0107976d62aaab8bca026d (diff)
downloadrails-38d26b0cb56d82093889efa95992a35ba3bb9f29.tar.gz
rails-38d26b0cb56d82093889efa95992a35ba3bb9f29.tar.bz2
rails-38d26b0cb56d82093889efa95992a35ba3bb9f29.zip
Move conditionals to separate tasks so they can be reused.
-rw-r--r--activerecord/lib/active_record/railties/databases.rake18
1 files changed, 11 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index f3cb2a971e..ee611f6a2a 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -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