forked from rails/rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
243 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 22 additions & 6 deletions
28
activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,43 @@ | ||
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 | ||
|
||
def encoding | ||
configuration['encoding'] || DEFAULT_ENCODING | ||
end | ||
|
||
def establish_master_connection | ||
establish_connection configuration.merge( | ||
'database' => 'postgres', | ||
'schema_search_path' => 'public' | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters