aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/tasks
diff options
context:
space:
mode:
authorSimon Jefford <simon.jefford@gmail.com>2012-06-18 20:49:52 +0100
committerSimon Jefford <simon.jefford@gmail.com>2012-06-19 15:15:47 +0100
commit363ab882165dc89a642c4fed01417bd64cdce0a8 (patch)
tree8f70dd921b3d88140ad1ee884ab6bee6d7f789c8 /activerecord/lib/active_record/tasks
parent4d69cdbdd75f5a9594055099770c4c3d0ffeb98d (diff)
downloadrails-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/tasks')
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb9
-rw-r--r--activerecord/lib/active_record/tasks/mysql_database_tasks.rb6
-rw-r--r--activerecord/lib/active_record/tasks/postgresql_database_tasks.rb6
-rw-r--r--activerecord/lib/active_record/tasks/sqlite_database_tasks.rb6
4 files changed, 24 insertions, 3 deletions
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