diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-27 01:20:17 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-27 01:20:17 -0300 |
commit | 4b8b8c1b4d1b516a9ebf8e19d5a14956c5654ac8 (patch) | |
tree | 2b81b319d5437ca0fe1fbb3b0ca97c8b3113502f | |
parent | 133754ef172706c10d6d1f9393d4fb1a1b19e2d7 (diff) | |
download | rails-4b8b8c1b4d1b516a9ebf8e19d5a14956c5654ac8.tar.gz rails-4b8b8c1b4d1b516a9ebf8e19d5a14956c5654ac8.tar.bz2 rails-4b8b8c1b4d1b516a9ebf8e19d5a14956c5654ac8.zip |
Only require the `:rails_env` task where is needed.
`:rails_env` tasks is not needed in all the tasks that depends of
`load_config`, only in the tasks that uses `Rails.env`.
Since `:rails_env` task set the `Rails.env` to be "development" if it is
not set we don't need the `||` statements too
Fix #7175.
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index e1ceeace04..ef8f577fc3 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -2,7 +2,7 @@ require 'active_support/core_ext/object/inclusion' require 'active_record' db_namespace = namespace :db do - task :load_config => :rails_env do + task :load_config do ActiveRecord::Base.configurations = Rails.application.config.database_configuration ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a @@ -36,7 +36,7 @@ db_namespace = namespace :db do end desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)' - task :create => :load_config do + task :create => [:load_config, :rails_env] do configs_for_environment.each { |config| create_database(config) } ActiveRecord::Base.establish_connection(configs_for_environment.first) end @@ -134,7 +134,7 @@ db_namespace = namespace :db do end desc 'Drops the database for the current Rails.env (use db:drop:all to drop all databases)' - task :drop => :load_config do + task :drop => [:load_config, :rails_env] do configs_for_environment.each { |config| drop_database_and_rescue(config) } end @@ -200,8 +200,8 @@ db_namespace = namespace :db do end desc 'Display status of migrations' - task :status => [:environment, :load_config] do - config = ActiveRecord::Base.configurations[Rails.env || 'development'] + task :status => [:environment, :load_config, :rails_env] do + config = ActiveRecord::Base.configurations[Rails.env] ActiveRecord::Base.establish_connection(config) unless ActiveRecord::Base.connection.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name) puts 'Schema migrations table does not exist yet.' @@ -253,8 +253,8 @@ db_namespace = namespace :db do end # desc "Retrieves the charset for the current environment's database" - task :charset => [:environment, :load_config] do - config = ActiveRecord::Base.configurations[Rails.env || 'development'] + task :charset => [:environment, :load_config, :rails_env] do + config = ActiveRecord::Base.configurations[Rails.env] case config['adapter'] when /mysql/ ActiveRecord::Base.establish_connection(config) @@ -271,8 +271,8 @@ db_namespace = namespace :db do end # desc "Retrieves the collation for the current environment's database" - task :collation => [:environment, :load_config] do - config = ActiveRecord::Base.configurations[Rails.env || 'development'] + task :collation => [:environment, :load_config, :rails_env] do + config = ActiveRecord::Base.configurations[Rails.env] case config['adapter'] when /mysql/ ActiveRecord::Base.establish_connection(config) @@ -311,7 +311,7 @@ db_namespace = namespace :db do namespace :fixtures do desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures." - task :load => [:environment, :load_config] do + task :load => [:environment, :load_config, :rails_env] do require 'active_record/fixtures' ActiveRecord::Base.establish_connection(Rails.env) @@ -349,7 +349,7 @@ db_namespace = namespace :db do namespace :schema do desc 'Create a db/schema.rb file that can be portably used against any DB supported by AR' - task :dump => [:environment, :load_config] do + task :dump => [:environment, :load_config, :rails_env] do require 'active_record/schema_dumper' filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb" File.open(filename, "w:utf-8") do |file| @@ -376,7 +376,7 @@ db_namespace = namespace :db do namespace :structure do desc 'Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql' - task :dump => [:environment, :load_config] do + task :dump => [:environment, :load_config, :rails_env] do abcs = ActiveRecord::Base.configurations filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql") case abcs[Rails.env]['adapter'] @@ -564,7 +564,7 @@ namespace :railties do puts "Copied migration #{migration.basename} from #{name}" end - ActiveRecord::Migration.copy( ActiveRecord::Migrator.migrations_paths.first, railties, + ActiveRecord::Migration.copy(ActiveRecord::Migrator.migrations_paths.first, railties, :on_skip => on_skip, :on_copy => on_copy) end end |