Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make `db:force_close_open_connections` work again and add support for…

… Postgresql 9.2
  • Loading branch information...
commit 1e5e193778b264bb1a39d21a497f8f3f5947a9c5 1 parent d47ac85
Jonathan Tron JonathanTron authored

Showing 1 changed file with 9 additions and 8 deletions. Show diff stats Hide diff stats

  1. +9 8 lib/sequel-rails/railties/database.rake
17 lib/sequel-rails/railties/database.rake
@@ -142,13 +142,14 @@ namespace :db do
142 142
143 143 desc 'Forcibly close any open connections to the test database'
144 144 task :force_close_open_connections => :environment do
145   - if Rails.env.test?
  145 + if db_for_current_env.database_type==:postgres
146 146 begin
147   - #Will only work on Postgres > 8.4
  147 + # Will only work on Postgres > 8.4
  148 + pid_column = db_for_current_env.server_version < 90200 ? "procpid" : "pid"
148 149 db_for_current_env.execute <<-SQL.gsub(/^\s{9}/,'')
149   - SELECT COUNT(pg_terminate_backend(procpid))
  150 + SELECT COUNT(pg_terminate_backend(#{pid_column}))
150 151 FROM pg_stat_activity
151   - WHERE datname = '#{db_config[:database]}';
  152 + WHERE datname = '#{db_for_current_env.opts[:database]}';
152 153 SQL
153 154 rescue => e
154 155 #Will raise an error as it kills existing process running this command
@@ -160,10 +161,10 @@ namespace :db do
160 161 namespace :test do
161 162 task :prepare => "db:abort_if_pending_migrations" do
162 163 Rails.env = 'test'
163   - Rake::Task['db:force_close_open_connections'].invoke
164   - Rake::Task['db:drop'].invoke
165   - Rake::Task['db:create'].invoke
166   - Rake::Task['db:schema:load'].invoke
  164 + Rake::Task['db:force_close_open_connections'].execute
  165 + Rake::Task['db:drop'].execute
  166 + Rake::Task['db:create'].execute
  167 + Rake::Task['db:schema:load'].execute
167 168 Sequel::DATABASES.each do |db|
168 169 db.disconnect
169 170 end

0 comments on commit 1e5e193

Please sign in to comment.
Something went wrong with that request. Please try again.