Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

JRUBY-3184: recreate_database for test database working for PG (Ryan …

…Bell)
  • Loading branch information...
commit 8ccea44108a0ad1ed051cc43b4a51e5ae1f95bb4 1 parent 87f33e5
@nicksieger nicksieger authored
View
1  History.txt
@@ -13,6 +13,7 @@
from court3nay)
- JRUBY-2715: Add create/drop database methods to Postgres (Peter Williams)
- JRUBY-3183: Fix structure dump for Postgres (Ryan Bell)
+- JRUBY-3184: recreate_database for test database working for PG (Ryan Bell)
- JRUBY-3186: disable referential integrity for PG (Ryan Bell)
- Authoritative repository now hosted at
git://github.com/nicksieger/activerecord-jdbc-adapter.git; rubyforge
View
17 lib/jdbc_adapter/jdbc.rake
@@ -64,6 +64,7 @@ namespace :db do
namespace :test do
redefine_task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
abcs = ActiveRecord::Base.configurations
+ abcs['test']['pg_params'] = '?allowEncodingChanges=true' if abcs['test']['adapter'] =~ /postgresql/i
ActiveRecord::Base.establish_connection(abcs["test"])
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') if abcs["test"]["adapter"] =~ /mysql/i
IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
@@ -73,8 +74,20 @@ namespace :db do
redefine_task :purge => :environment do
abcs = ActiveRecord::Base.configurations
- ActiveRecord::Base.establish_connection(abcs["test"])
- db = ActiveRecord::Base.connection.database_name
+ config = abcs['test'].dup
+ if config['adapter'] =~ /postgresql/i
+ if config['url']
+ db = config['url'][/\/([^\/]*)$/, 1]
+ config['url'][/\/([^\/]*)$/, 1] if db_name
+ else
+ db = config['database']
+ config['database'] = 'postgres'
+ end
+ ActiveRecord::Base.establish_connection(config)
+ else
+ ActiveRecord::Base.establish_connection(config)
+ db = ActiveRecord::Base.connection.database_name
+ end
ActiveRecord::Base.connection.recreate_database(db)
end
end
View
1  lib/jdbc_adapter/jdbc_postgre.rb
@@ -7,6 +7,7 @@ def postgresql_connection(config)
config[:host] ||= "localhost"
config[:port] ||= 5432
config[:url] ||= "jdbc:postgresql://#{config[:host]}:#{config[:port]}/#{config[:database]}"
+ config[:url] << config[:pg_params] if config[:pg_params]
config[:driver] ||= "org.postgresql.Driver"
jdbc_connection(config)
end
Please sign in to comment.
Something went wrong with that request. Please try again.