From bca52b05af8ef757e9574f833217c0051ee21a50 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 17 Jun 2012 17:39:12 +0200 Subject: db:drop and some of db:test:purge. --- .../tasks/postgresql_database_tasks.rb | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record/tasks/postgresql_database_tasks.rb') 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 -- cgit v1.2.3