diff options
author | Pat Allan <pat@freelancing-gods.com> | 2012-06-17 17:39:12 +0200 |
---|---|---|
committer | Pat Allan <pat@freelancing-gods.com> | 2012-06-17 17:39:12 +0200 |
commit | bca52b05af8ef757e9574f833217c0051ee21a50 (patch) | |
tree | 2c8cf16bd0077a565445af4e438dd5328e54daa2 /activerecord/lib/active_record/tasks/postgresql_database_tasks.rb | |
parent | e678d413bc14e9a38cd9818c7cf727339b2db9e7 (diff) | |
download | rails-bca52b05af8ef757e9574f833217c0051ee21a50.tar.gz rails-bca52b05af8ef757e9574f833217c0051ee21a50.tar.bz2 rails-bca52b05af8ef757e9574f833217c0051ee21a50.zip |
db:drop and some of db:test:purge.
Diffstat (limited to 'activerecord/lib/active_record/tasks/postgresql_database_tasks.rb')
-rw-r--r-- | activerecord/lib/active_record/tasks/postgresql_database_tasks.rb | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb index 4e64a5e346..c3c5b2f2f5 100644 --- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb @@ -1,22 +1,31 @@ class ActiveRecord::Tasks::PostgreSQLDatabaseTasks DEFAULT_ENCODING = ENV['CHARSET'] || 'utf8' - delegate :connection, :establish_connection, :to => ActiveRecord::Base + delegate :connection, :establish_connection, :clear_active_connections!, + :to => ActiveRecord::Base def initialize(configuration) @configuration = configuration end - def create - establish_connection configuration.merge( - 'database' => 'postgres', - 'schema_search_path' => 'public' - ) + def create(master_established = false) + establish_master_connection unless master_established connection.create_database configuration['database'], configuration.merge('encoding' => encoding) establish_connection configuration end + def drop + establish_master_connection + connection.drop_database configuration['database'] + end + + def purge + clear_active_connections! + drop + create true + end + private attr_reader :configuration @@ -24,4 +33,11 @@ class ActiveRecord::Tasks::PostgreSQLDatabaseTasks def encoding configuration['encoding'] || DEFAULT_ENCODING end + + def establish_master_connection + establish_connection configuration.merge( + 'database' => 'postgres', + 'schema_search_path' => 'public' + ) + end end |