diff options
author | kennyj <kennyj@gmail.com> | 2012-06-29 20:35:49 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2012-07-01 00:56:50 +0900 |
commit | bece59e36df9a267046bac377001b6ff610e8151 (patch) | |
tree | e821a073df33b9e9641ae44954b4cef80995d4d4 /activerecord/lib/active_record | |
parent | 05c7e0ae6425fc5cbc9cb50bd035a3ee80e8b4b3 (diff) | |
download | rails-bece59e36df9a267046bac377001b6ff610e8151.tar.gz rails-bece59e36df9a267046bac377001b6ff610e8151.tar.bz2 rails-bece59e36df9a267046bac377001b6ff610e8151.zip |
Extract collation tasks to database tasks.
Diffstat (limited to 'activerecord/lib/active_record')
4 files changed, 20 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 3e351bf0e2..52fa4fb8be 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -148,14 +148,9 @@ db_namespace = namespace :db do # desc "Retrieves the collation for the current environment's database" task :collation => [:environment, :load_config] do - config = ActiveRecord::Base.configurations[Rails.env || 'development'] - case config['adapter'] - when /mysql/ - ActiveRecord::Base.establish_connection(config) - puts ActiveRecord::Base.connection.collation - else - $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch' - end + puts ActiveRecord::Tasks::DatabaseTasks.collation_current + ensure NoMethodError + $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch' end desc 'Retrieves the current schema version number' diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index 999b2ebc85..f1241502f5 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -56,6 +56,15 @@ module ActiveRecord class_for_adapter(configuration['adapter']).new(*arguments).charset end + def collation_current(environment = Rails.env) + collation ActiveRecord::Base.configurations[environment] + end + + def collation(*arguments) + configuration = arguments.first + class_for_adapter(configuration['adapter']).new(*arguments).collation + end + def purge(configuration) class_for_adapter(configuration['adapter']).new(configuration).purge end diff --git a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb index b39cd2282f..bf62dfd5b5 100644 --- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb @@ -44,6 +44,10 @@ module ActiveRecord connection.charset end + def collation + connection.collation + end + def structure_dump(filename) establish_connection configuration File.open(filename, "w:utf-8") { |f| f << ActiveRecord::Base.connection.structure_dump } diff --git a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb index a210392e53..4139460273 100644 --- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb @@ -29,6 +29,10 @@ module ActiveRecord connection.encoding end + def collation + connection.collate + end + def purge clear_active_connections! drop |