mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Drop Postgres database with AR connection
1. Works faster than issuing shell commands. 2. Attempts to drop the database before creating it. This fixes some ugly test output which warns that given database already exists.
This commit is contained in:
parent
f318781a77
commit
6c59ff2bac
1 changed files with 1 additions and 1 deletions
|
@ -14,6 +14,7 @@ module PostgreSQLHelper
|
|||
@encoding = default_config['encoding'] || ENV['CHARSET'] || 'utf8'
|
||||
begin
|
||||
establish_connection(default_config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
||||
ActiveRecord::Base.connection.drop_database(default_config['database']) rescue nil
|
||||
ActiveRecord::Base.connection.create_database(default_config['database'], default_config.merge('encoding' => @encoding))
|
||||
rescue Exception => e
|
||||
$stderr.puts e, *(e.backtrace)
|
||||
|
@ -32,7 +33,6 @@ module PostgreSQLHelper
|
|||
end
|
||||
|
||||
def active_record_pg_migrate
|
||||
`dropdb #{default_config['database']}`
|
||||
create_db
|
||||
establish_connection
|
||||
ActiveRecord::Migrator.migrate 'spec/support/active_record/migrations'
|
||||
|
|
Loading…
Reference in a new issue