Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move conditionals to separate tasks so they can be reused.

  • Loading branch information...
commit 38d26b0cb56d82093889efa95992a35ba3bb9f29 1 parent 272f2b7
@tenderlove tenderlove authored
Showing with 11 additions and 7 deletions.
  1. +11 −7 activerecord/lib/active_record/railties/databases.rake
View
18 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

3 comments on commit 38d26b0

@guilleiguaran

Looks like this commit makes Sam sad

@rubys

It causes rake db:seed to delete the database, recreate the database, and re-run all migrations: before => after.

Please sign in to comment.
Something went wrong with that request. Please try again.