diff options
author | Simon Jefford <simon.jefford@gmail.com> | 2012-06-18 20:49:52 +0100 |
---|---|---|
committer | Simon Jefford <simon.jefford@gmail.com> | 2012-06-19 15:15:47 +0100 |
commit | 363ab882165dc89a642c4fed01417bd64cdce0a8 (patch) | |
tree | 8f70dd921b3d88140ad1ee884ab6bee6d7f789c8 /activerecord/lib/active_record | |
parent | 4d69cdbdd75f5a9594055099770c4c3d0ffeb98d (diff) | |
download | rails-363ab882165dc89a642c4fed01417bd64cdce0a8.tar.gz rails-363ab882165dc89a642c4fed01417bd64cdce0a8.tar.bz2 rails-363ab882165dc89a642c4fed01417bd64cdce0a8.zip |
Refactor db:charset task
In a similar vein to Pat's work on create, drop etc, the db:charset
task is now a one liner in databases.rake
Diffstat (limited to 'activerecord/lib/active_record')
5 files changed, 25 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 539836e9ed..d513dca1f5 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -143,20 +143,7 @@ db_namespace = namespace :db do # desc "Retrieves the charset for the current environment's database" task :charset => [: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.charset - when /postgresql/ - ActiveRecord::Base.establish_connection(config) - puts ActiveRecord::Base.connection.encoding - when /sqlite/ - ActiveRecord::Base.establish_connection(config) - puts ActiveRecord::Base.connection.encoding - else - $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch' - end + puts ActiveRecord::Tasks::DatabaseTasks.charset_current end # desc "Retrieves the collation for the current environment's database" diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index 24fe4134e0..5101871cc0 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -47,6 +47,15 @@ module ActiveRecord } end + def charset_current(environment = Rails.env) + charset ActiveRecord::Base.configurations[environment] + end + + def charset(*arguments) + configuration = arguments.first + class_for_adapter(configuration['adapter']).new(*arguments).charset + 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 646034f313..361437fdc7 100644 --- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb @@ -40,6 +40,10 @@ module ActiveRecord connection.recreate_database configuration['database'], creation_options end + def charset + connection.charset + end + private def configuration @@ -90,4 +94,4 @@ IDENTIFIED BY '#{configuration['password']}' WITH GRANT OPTION; end end end -end
\ No newline at end of file +end diff --git a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb index ddc5b9fc5c..8d4249fd79 100644 --- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb @@ -23,6 +23,10 @@ module ActiveRecord connection.drop_database configuration['database'] end + def charset + connection.encoding + end + def purge clear_active_connections! drop @@ -47,4 +51,4 @@ module ActiveRecord end end end -end
\ No newline at end of file +end diff --git a/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb b/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb index 85f4c12829..d9332eaf1b 100644 --- a/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/sqlite_database_tasks.rb @@ -27,6 +27,10 @@ module ActiveRecord end alias :purge :drop + def charset + connection.encoding + end + private def configuration @@ -38,4 +42,4 @@ module ActiveRecord end end end -end
\ No newline at end of file +end |