Permalink
Browse files

Don't require Rails.env in order to use AR::Tasks::DatabaseTasks

  • Loading branch information...
1 parent 414ab0c commit 20f1495af8a3461dab4c8378a2c774d694b17c51 @drogus drogus committed Apr 24, 2013
@@ -37,6 +37,7 @@ class Railtie < Rails::Railtie # :nodoc:
rake_tasks do
require "active_record/base"
+ ActiveRecord::Tasks::DatabaseTasks.env = Rails.env
ActiveRecord::Tasks::DatabaseTasks.db_dir = Rails.application.config.paths["db"].first
ActiveRecord::Tasks::DatabaseTasks.seed_loader = Rails.application
ActiveRecord::Tasks::DatabaseTasks.database_configuration = Rails.application.config.database_configuration
@@ -17,6 +17,7 @@ class DatabaseNotSupported < StandardError; end # :nodoc:
#
# The possible config values are the following:
#
+ # * env: current environment
# * db_dir: your 'db' directory
# * seed_loader: an object which will load seeds, it needs to respond to `load_seed` method
# * database_configuration: configuration of your databases (as in config/database.yml)
@@ -36,7 +37,7 @@ module DatabaseTasks
attr_writer :current_config
attr_accessor :database_configuration, :migrations_paths, :seed_loader, :db_dir,
- :fixtures_path
+ :fixtures_path, :env
LOCAL_HOSTS = ['127.0.0.1', 'localhost']
@@ -54,7 +55,7 @@ def register_task(pattern, task)
register_task(/(oci|oracle)/, ActiveRecord::Tasks::OracleDatabaseTasks)
def current_config(options = {})
- options.reverse_merge! :env => Rails.env
+ options.reverse_merge! :env => env
if options.has_key?(:config)
@current_config = options[:config]
else
@@ -80,7 +81,7 @@ def create_all
each_local_configuration { |configuration| create configuration }
end
- def create_current(environment = Rails.env)
+ def create_current(environment = env)
each_current_configuration(environment) { |configuration|
create configuration
}
@@ -103,7 +104,7 @@ def drop_all
each_local_configuration { |configuration| drop configuration }
end
- def drop_current(environment = Rails.env)
+ def drop_current(environment = env)
each_current_configuration(environment) { |configuration|
drop configuration
}
@@ -113,7 +114,7 @@ def drop_database_url
drop database_url_config
end
- def charset_current(environment = Rails.env)
+ def charset_current(environment = env)
charset ActiveRecord::Base.configurations[environment]
end
@@ -122,7 +123,7 @@ def charset(*arguments)
class_for_adapter(configuration['adapter']).new(*arguments).charset
end
- def collation_current(environment = Rails.env)
+ def collation_current(environment = env)
collation ActiveRecord::Base.configurations[environment]
end

0 comments on commit 20f1495

Please sign in to comment.