pg_tasks 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc265a9b51988c66412de5651644fe6427761bd0
4
- data.tar.gz: 7326fe644b0d418c17707e6f80600c3554ba9c61
3
+ metadata.gz: 12e52f1af8a55af227b0925b29096958f20826bc
4
+ data.tar.gz: 4e8258d91b992df3c6827c460422e464523b21e0
5
5
  SHA512:
6
- metadata.gz: b005994e668eb75f856f12ad35b17d671cea87a31779ee6bd519a7035147b01dd478f95d150f800e0b4faee7920858e50dd1289403c08ea21c4e0d7e99a826a7
7
- data.tar.gz: 5bfd6120421f4f5606a274e7840c23c474846eaed9150d04e60b898c594d068f9bcb02b1d0415c959e504c84a5df5317d8e709f5ccb68f50ce19b36b4c974462
6
+ metadata.gz: 4df1c4897e695827b180621f4b187b95cbea3c8efbd476d302fef310df75652428664e8dacee6fc664acdf40cc2ccaffb9f1fe53f8828406d3aa842355cb66ce
7
+ data.tar.gz: 3b584e9d0df49843bea70d23bc6b05808d23a443dc0173f2ad9ec6897c7098795fadf89aaaff992e4c956ffa554fa44b6e53c8f68ce0a19bf114becc3fd7d48a
@@ -43,6 +43,10 @@ module PgTasks
43
43
  end
44
44
  end
45
45
 
46
+ def terminate_connections
47
+ ActiveRecord::Tasks::DatabaseTasks.terminate_connections current_config
48
+ end
49
+
46
50
  private
47
51
 
48
52
  def current_config
@@ -118,6 +122,20 @@ module ActiveRecord
118
122
  "has been restored to '#{filename}'"
119
123
  end
120
124
  end
125
+
126
+ def terminate_connections
127
+ set_psql_env
128
+ database = configuration['database']
129
+ command = "psql -c \"SELECT pg_terminate_backend(pg_stat_activity.pid) " \
130
+ ' FROM pg_stat_activity ' \
131
+ "WHERE pg_stat_activity.datname = '#{database}' " \
132
+ " AND pid <> pg_backend_pid();\" '#{database}'"
133
+ unless Kernel.system(command)
134
+ raise 'Error during terminate_connections'
135
+ else
136
+ $stdout.puts "Connections to '#{database}' have been terminated."
137
+ end
138
+ end
121
139
  end
122
140
  end
123
141
  end
@@ -135,6 +153,12 @@ module ActiveRecord
135
153
  rescue Exception => error
136
154
  $stderr.puts error, *(error.backtrace)
137
155
  end
156
+
157
+ def terminate_connections(*arguments)
158
+ configuration = arguments.first
159
+ class_for_adapter(configuration['adapter']) \
160
+ .new(*arguments).send :terminate_connections
161
+ end
138
162
  end
139
163
  end
140
164
  end
@@ -7,5 +7,5 @@
7
7
  #++
8
8
 
9
9
  module PgTasks
10
- VERSION = '1.1.0'
10
+ VERSION = '1.2.0'
11
11
  end
@@ -14,6 +14,10 @@ namespace :db do
14
14
  PgTasks.truncate_tables
15
15
  end
16
16
 
17
+ task terminate_connections: [:environment, :load_config] do
18
+ PgTasks.terminate_connections
19
+ end
20
+
17
21
  namespace :data do
18
22
  task dump: [:environment, :load_config] do
19
23
  PgTasks.data_dump ENV['FILE']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Schank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails