pg_connections_terminate 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 865982acc408f67fc9e1f02e2e8cb3c63e1c8dd69b987c827ed2aa39000f5b20
4
+ data.tar.gz: 4d8a387814429c906179dbc931486208901ebac1c392438b56b4754e08cbfebe
5
+ SHA512:
6
+ metadata.gz: b83c6f8970dc038ebc7e58aef4e836f330bd78bdef2053fe5ee0edc21dd8cd1e71732570862c2a700377fa5affe09db8f8034d786edcf952a67cac25b9c4cb0d
7
+ data.tar.gz: 8cac15562efb242d5d1422dd4ad01ae6b5573172c54da9c2044652aa52264d66162b084739de80e08e5047323d80aad259aa99f07998d5686aa392dad04768f0
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [0.1.0] - 2024-04-13
2
+
3
+ - Initial release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2024] [Michał Zaporski]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # PgConnectionsTerminate
2
+
3
+ This gem adds a new rake task which terminates all the connections with the Rails app database.
4
+ Database is selected based on the `config/database.yml` and the `RAILS_ENV`.
5
+
6
+ ## Installation
7
+
8
+ Install the gem and add to the application's Gemfile by executing:
9
+
10
+ ```sh
11
+ $ bundle add pg_connections_terminate
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Run like any other Rails rake task:
17
+
18
+ ```sh
19
+ $ bundle exec bin/rails db:connections:terminate RAILS_ENV=test
20
+ ```
21
+
22
+ ## Contributing
23
+
24
+ Bug reports and pull requests are welcome on GitHub at https://github.com/MichalZaporski/pg_connections_terminate.
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ::PgConnectionsTerminate
4
+ class Railtie < ::Rails::Railtie
5
+ rake_tasks do
6
+ namespace :db do
7
+ namespace :connections do
8
+ desc 'Terminates all the connections with the database from config/database.yml for the current RAILS_ENV'
9
+ task terminate: :environment do
10
+ db_name = ::Rails.configuration.database_configuration[::Rails.env]['database']
11
+ query = <<~SQL
12
+ SELECT pg_terminate_backend(pg_stat_activity.pid)
13
+ FROM pg_stat_activity
14
+ WHERE pg_stat_activity.datname = '#{db_name}'
15
+ AND pid <> pg_backend_pid();
16
+ SQL
17
+
18
+ ::ActiveRecord::Base.connection.execute(query)
19
+
20
+ puts "All connections with the \"#{db_name}\" database have been terminated."
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ::PgConnectionsTerminate
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'pg_connections_terminate/version'
4
+ require_relative 'pg_connections_terminate/railtie'
5
+
6
+ module ::PgConnectionsTerminate; end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/pg_connections_terminate/version'
4
+
5
+ ::Gem::Specification.new do |spec|
6
+ spec.name = 'pg_connections_terminate'
7
+ spec.version = ::PgConnectionsTerminate::VERSION
8
+ spec.authors = ['Michał Zaporski']
9
+ spec.email = ['focus16k@gmail.com']
10
+
11
+ spec.summary = 'Rails rake task for terminating postgresql connections.'
12
+ spec.description = 'This gem adds a new rake task which terminates all the connections with the Rails app database.'
13
+ spec.homepage = 'https://github.com/MichalZaporski/pg_connections_terminate'
14
+ spec.required_ruby_version = '>= 2.6.0'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = ::Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (::File.expand_path(f) == __FILE__) ||
24
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .gitlab-ci.yml appveyor Gemfile])
25
+ end
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| ::File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pg_connections_terminate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michał Zaporski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem adds a new rake task which terminates all the connections with
14
+ the Rails app database.
15
+ email:
16
+ - focus16k@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - LICENSE
23
+ - README.md
24
+ - lib/pg_connections_terminate.rb
25
+ - lib/pg_connections_terminate/railtie.rb
26
+ - lib/pg_connections_terminate/version.rb
27
+ - pg_connections_terminate.gemspec
28
+ homepage: https://github.com/MichalZaporski/pg_connections_terminate
29
+ licenses: []
30
+ metadata:
31
+ homepage_uri: https://github.com/MichalZaporski/pg_connections_terminate
32
+ source_code_uri: https://github.com/MichalZaporski/pg_connections_terminate
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 2.6.0
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.5.3
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Rails rake task for terminating postgresql connections.
52
+ test_files: []