rails-pg-extras 4.4.0 → 4.8.1

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
  SHA256:
3
- metadata.gz: 0a0259a817155746ae3dda5a13fd1e6c8e0421dad029dd2c6100222379dad76f
4
- data.tar.gz: 5ffdc7d923d458bab991439a65adf91ff3e752e8e90280c6e3faae57d36762a7
3
+ metadata.gz: acfc146396c33697f24aa0e96d251c77fd94e2a5d10a8154dcff9df02a981ac8
4
+ data.tar.gz: 5290474635b58a4e35afd3c075726b24e75a6194acd691e5b90b5b3289f2b5f1
5
5
  SHA512:
6
- metadata.gz: a6a55fcb7e8cc126859f1f45f4ba38f9562f1bded1e4aa6287e3728926cc3eb598552d4cdcc311104e811b513f20a71f52d29964dd6f0137df68a2699e9ef7ab
7
- data.tar.gz: 305dc8c57cace4845795b051afca373103765181a1121203d9963261a0be18b50d6335355a60988be745d16d19ecd9f30ac506f4cff15c5265c38cdca039316a
6
+ metadata.gz: 3db2562f135d7b904239f5481d5050f1404062b679fa9dc1399379bea58f66c981d7adadee8d5af34ff4e5c0ffc10f6cd1de2c3fab03923083c45fa11d24785b
7
+ data.tar.gz: 91b734c2c9bc9e6678d50def9cc4603e5444f35b16ec90514e14644954fa1d8d8e4b014c287dc2beb2cb9edfc3cadd29f517ad3f4fd42a37872304b91c5c553b
data/.circleci/config.yml CHANGED
@@ -2,39 +2,47 @@ version: 2
2
2
  jobs:
3
3
  test:
4
4
  docker:
5
- - image: circleci/ruby:2.6.5
5
+ - image: cimg/ruby:2.7.6
6
6
  environment:
7
7
  DATABASE_URL: postgresql://postgres:secret@localhost:5432/rails-pg-extras-test
8
- - image: circleci/postgres:11.5
8
+ - image: cimg/postgres:11.15
9
9
  command: postgres -c shared_preload_libraries=pg_stat_statements
10
10
  name: postgres11
11
11
  environment:
12
12
  POSTGRES_USER: postgres
13
13
  POSTGRES_DB: rails-pg-extras-test
14
14
  POSTGRES_PASSWORD: secret
15
- - image: circleci/postgres:12.7
15
+ - image: cimg/postgres:12.10
16
16
  command: postgres -c shared_preload_libraries=pg_stat_statements
17
17
  name: postgres12
18
18
  environment:
19
19
  POSTGRES_USER: postgres
20
20
  POSTGRES_DB: rails-pg-extras-test
21
21
  POSTGRES_PASSWORD: secret
22
- - image: circleci/postgres:13.3
22
+ - image: cimg/postgres:13.6
23
23
  command: postgres -c shared_preload_libraries=pg_stat_statements
24
24
  name: postgres13
25
25
  environment:
26
26
  POSTGRES_USER: postgres
27
27
  POSTGRES_DB: rails-pg-extras-test
28
28
  POSTGRES_PASSWORD: secret
29
+ - image: cimg/postgres:14.2
30
+ command: postgres -c shared_preload_libraries=pg_stat_statements
31
+ name: postgres14
32
+ environment:
33
+ POSTGRES_USER: postgres
34
+ POSTGRES_DB: rails-pg-extras-test
35
+ POSTGRES_PASSWORD: secret
29
36
  parallelism: 1
30
37
  steps:
31
38
  - checkout
32
39
  - run: gem update --system
33
40
  - run: gem install bundler
34
- - run: bundle config set --local path 'vendor/bundle'
35
- - run: bundle install
36
41
  - run: sudo apt-get update --allow-releaseinfo-change
37
42
  - run: sudo apt install postgresql-client
43
+ - run: sudo apt install libpq-dev
44
+ - run: bundle config set --local path 'vendor/bundle'
45
+ - run: bundle install
38
46
  - run: dockerize -wait tcp://postgres11:5432 -timeout 1m
39
47
  - run:
40
48
  name: Run specs for PG 11
@@ -51,6 +59,11 @@ jobs:
51
59
  environment:
52
60
  DATABASE_URL: postgresql://postgres:secret@postgres13:5432/rails-pg-extras-test
53
61
  command: bundle exec rspec spec/
62
+ - run:
63
+ name: Run specs for PG 14
64
+ environment:
65
+ DATABASE_URL: postgresql://postgres:secret@postgres14:5432/rails-pg-extras-test
66
+ command: bundle exec rspec spec/
54
67
  workflows:
55
68
  version: 2
56
69
  test:
data/README.md CHANGED
@@ -20,7 +20,7 @@ Alternative versions:
20
20
 
21
21
  - [Elixir](https://github.com/pawurb/ecto_psql_extras)
22
22
 
23
- - [Python](https://github.com/pawurb/ecto_psql_extras)
23
+ - [Python Flask](https://github.com/nickjj/flask-pg-extras)
24
24
 
25
25
  - [Haskell](https://github.com/pawurb/haskell-pg-extras)
26
26
 
@@ -119,7 +119,7 @@ You can enable UI using a Rails engine by adding the following code in `config/r
119
119
  mount RailsPgExtras::Web::Engine, at: 'pg_extras'
120
120
  ```
121
121
 
122
- You can enable HTTP basic auth by specifying `RAILS_PG_EXTRAS_USER` and `RAILS_PG_EXTRAS_PASSWORD` variables.
122
+ You can enable HTTP basic auth by specifying `RAILS_PG_EXTRAS_USER` and `RAILS_PG_EXTRAS_PASSWORD` variables. Authentication is mandatory unless you specify `RAILS_PG_EXTRAS_PUBLIC_DASHBOARD=true`.
123
123
 
124
124
  You can configure available web actions in `config/initializers/rails_pg_extras.rb`:
125
125
 
@@ -128,7 +128,7 @@ RailsPgExtras.configure do |config|
128
128
  # Rails-pg-extras does not enable all the web actions by default. You can check all available actions via `RailsPgExtras::Web::ACTIONS`.
129
129
  # For example, you may want to enable the dangerous `kill_all` action.
130
130
 
131
- config.enabled_web_actions = %i[kill_all pg_stat_statements_reset enable_extensions]
131
+ config.enabled_web_actions = %i[kill_all pg_stat_statements_reset add_extensions]
132
132
  end
133
133
  ```
134
134
 
@@ -286,14 +286,14 @@ RailsPgExtras.locks
286
286
 
287
287
  $ rake pg_extras:locks
288
288
 
289
- procpid | relname | transactionid | granted | query_snippet | mode | age
290
- ---------+---------+---------------+---------+-----------------------+-------------------------------------
291
- 31776 | | | t | <IDLE> in transaction | ExclusiveLock | 00:19:29.837898
292
- 31776 | | 1294 | t | <IDLE> in transaction | RowExclusiveLock | 00:19:29.837898
293
- 31912 | | | t | select * from hello; | ExclusiveLock | 00:19:17.94259
294
- 3443 | | | t | +| ExclusiveLock | 00:00:00
295
- | | | | select +| |
296
- | | | | pg_stat_activi | |
289
+ procpid | relname | transactionid | granted | query_snippet | mode | age | application |
290
+ ---------+---------+---------------+---------+-----------------------+------------------------------------------------------
291
+ 31776 | | | t | <IDLE> in transaction | ExclusiveLock | 00:19:29.837898 | bin/rails
292
+ 31776 | | 1294 | t | <IDLE> in transaction | RowExclusiveLock | 00:19:29.837898 | bin/rails
293
+ 31912 | | | t | select * from hello; | ExclusiveLock | 00:19:17.94259 | bin/rails
294
+ 3443 | | | t | +| ExclusiveLock | 00:00:00 | bin/sidekiq
295
+ | | | | select +| | |
296
+ | | | | pg_stat_activi | | |
297
297
  (4 rows)
298
298
  ```
299
299
 
data/Rakefile CHANGED
@@ -5,6 +5,6 @@ RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  desc 'Test all PG versions'
7
7
  task :test_all do
8
- system("PG_VERSION=11 bundle exec rspec spec/ && PG_VERSION=12 bundle exec rspec spec/ && PG_VERSION=13 bundle exec rspec spec/")
8
+ system("PG_VERSION=11 bundle exec rspec spec/ && PG_VERSION=12 bundle exec rspec spec/ && PG_VERSION=13 bundle exec rspec spec/ && PG_VERSION=14 bundle exec rspec spec/")
9
9
  end
10
10
 
@@ -3,6 +3,7 @@ require "rails_pg_extras/version"
3
3
 
4
4
  module RailsPgExtras::Web
5
5
  class ApplicationController < ActionController::Base
6
+ before_action :validate_credentials!
6
7
  layout "rails_pg_extras/web/application"
7
8
 
8
9
  REQUIRED_EXTENSIONS = {
@@ -14,7 +15,13 @@ module RailsPgExtras::Web
14
15
  ACTIONS = %i[kill_all pg_stat_statements_reset add_extensions]
15
16
 
16
17
  if ENV['RAILS_PG_EXTRAS_USER'].present? && ENV['RAILS_PG_EXTRAS_PASSWORD'].present?
17
- http_basic_authenticate_with name: ENV['RAILS_PG_EXTRAS_USER'], password: ENV['RAILS_PG_EXTRAS_PASSWORD']
18
+ http_basic_authenticate_with name: ENV.fetch('RAILS_PG_EXTRAS_USER'), password: ENV.fetch('RAILS_PG_EXTRAS_PASSWORD')
19
+ end
20
+
21
+ def validate_credentials!
22
+ if (ENV['RAILS_PG_EXTRAS_USER'].blank? || ENV['RAILS_PG_EXTRAS_PASSWORD'].blank?) && ENV["RAILS_PG_EXTRAS_PUBLIC_DASHBOARD"] != "true"
23
+ raise "Missing credentials for rails-pg-extras dashboard! If you want to enable public dashboard please set RAILS_PG_EXTRAS_PUBLIC_DASHBOARD=true"
24
+ end
18
25
  end
19
26
  end
20
27
  end
@@ -21,7 +21,7 @@ module RailsPgExtras::Web
21
21
  private
22
22
 
23
23
  def load_queries
24
- @all_queries = (RailsPgExtras::QUERIES - ACTIONS).inject({}) do |memo, query_name|
24
+ @all_queries = (RailsPgExtras::QUERIES - RailsPgExtras::Web::ACTIONS).inject({}) do |memo, query_name|
25
25
  unless query_name.in? %i[mandelbrot]
26
26
  memo[query_name] = { disabled: query_disabled?(query_name) }
27
27
  end
@@ -5,7 +5,7 @@
5
5
  <% end %>
6
6
  </div>
7
7
 
8
- <% if RailsPgExtras::Web.action_enabled?(:enable_extensions) %>
8
+ <% if RailsPgExtras::Web.action_enabled?(:add_extensions) %>
9
9
  <%= link_to "Enable extensions", add_extensions_action_path,
10
10
  method: "post",
11
11
  data: {
@@ -15,7 +15,7 @@
15
15
  %>
16
16
  <% end %>
17
17
 
18
- <% if RailsPgExtras::Web.action_enabled?(:pg_stat_statements_reset) %>
18
+ <% if RailsPgExtras::Web.action_enabled?(:pg_stat_statements_reset) && unavailable_extensions.exclude?(:pg_stat_statements) %>
19
19
  <%= link_to "pg_stat_statements_reset", pg_stat_statements_reset_action_path,
20
20
  method: "post",
21
21
  data: {
@@ -1,11 +1,11 @@
1
- <%= form_with url: queries_path, id: "queries", method: :get do |f| %>
2
- <%= f.select :query_name, options_for_select(@all_queries, params[:query_name]),
3
- {prompt: "--- select query ---"},
4
- {class: "border p-2 font-bold", autofocus: true}
1
+ <%= form_tag queries_path, id: "queries", method: :get do |f| %>
2
+ <%= select_tag :query_name, options_for_select(@all_queries, params[:query_name]),
3
+ {prompt: "--- select query ---", class: "border p-2 font-bold", autofocus: true}
5
4
  %>
6
5
  <% end %>
7
- <script>
6
+
7
+ <%= javascript_tag nonce: true do -%>
8
8
  document.getElementById('queries').addEventListener('change', (e) => {
9
9
  e.target.form.submit()
10
10
  })
11
- </script>
11
+ <% end -%>
@@ -2,7 +2,7 @@ version: '3'
2
2
 
3
3
  services:
4
4
  postgres11:
5
- image: postgres:11.5-alpine
5
+ image: postgres:11.16-alpine
6
6
  command: postgres -c shared_preload_libraries=pg_stat_statements
7
7
  environment:
8
8
  POSTGRES_USER: postgres
@@ -11,7 +11,7 @@ services:
11
11
  ports:
12
12
  - '5432:5432'
13
13
  postgres12:
14
- image: postgres:12.7-alpine
14
+ image: postgres:12.11-alpine
15
15
  command: postgres -c shared_preload_libraries=pg_stat_statements
16
16
  environment:
17
17
  POSTGRES_USER: postgres
@@ -20,7 +20,7 @@ services:
20
20
  ports:
21
21
  - '5433:5432'
22
22
  postgres13:
23
- image: postgres:13.3-alpine
23
+ image: postgres:13.7-alpine
24
24
  command: postgres -c shared_preload_libraries=pg_stat_statements
25
25
  environment:
26
26
  POSTGRES_USER: postgres
@@ -28,3 +28,12 @@ services:
28
28
  POSTGRES_PASSWORD: secret
29
29
  ports:
30
30
  - '5434:5432'
31
+ postgres14:
32
+ image: postgres:14.3-alpine
33
+ command: postgres -c shared_preload_libraries=pg_stat_statements
34
+ environment:
35
+ POSTGRES_USER: postgres
36
+ POSTGRES_DB: rails-pg-extras-test
37
+ POSTGRES_PASSWORD: secret
38
+ ports:
39
+ - '5435:5432'
@@ -3,35 +3,25 @@
3
3
  require 'rails-pg-extras'
4
4
 
5
5
  namespace :pg_extras do
6
- task :establish_connection do
7
- if ENV['DATABASE_URL'].present?
8
- ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
9
- else
10
- db_config_file = File.read('config/database.yml')
11
- db_config = YAML::load(ERB.new(db_config_file).result, aliases: true)
12
- ActiveRecord::Base.establish_connection(db_config[Rails.env])
13
- end
14
- end
15
-
16
6
  RailsPgExtras::QUERIES.each do |query_name|
17
7
  desc RubyPgExtras.description_for(query_name: query_name)
18
- task query_name.to_sym => :establish_connection do
8
+ task query_name.to_sym => :environment do
19
9
  RailsPgExtras.public_send(query_name)
20
10
  end
21
11
  end
22
12
 
23
13
  desc "Generate a PostgreSQL healthcheck report"
24
- task diagnose: :establish_connection do
14
+ task diagnose: :environment do
25
15
  RailsPgExtras.diagnose
26
16
  end
27
17
 
28
18
  desc "Display tables metadata metrics"
29
- task table_info: :establish_connection do
19
+ task table_info: :environment do
30
20
  RailsPgExtras.table_info
31
21
  end
32
22
 
33
23
  desc "Display indexes metadata metrics"
34
- task index_info: :establish_connection do
24
+ task index_info: :environment do
35
25
  RailsPgExtras.index_info
36
26
  end
37
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPgExtras
4
- VERSION = "4.4.0"
4
+ VERSION = "4.8.1"
5
5
  end
@@ -3,5 +3,7 @@ require 'rails'
3
3
  module RailsPgExtras::Web
4
4
  class Engine < ::Rails::Engine
5
5
  isolate_namespace RailsPgExtras::Web
6
+
7
+ config.middleware.use ActionDispatch::Flash
6
8
  end
7
9
  end
@@ -2,7 +2,7 @@ require "rails_pg_extras/web/engine"
2
2
 
3
3
  module RailsPgExtras
4
4
  module Web
5
- ACTIONS = %i[kill_all pg_stat_statements_reset enable_extensions].freeze
5
+ ACTIONS = %i[kill_all pg_stat_statements_reset add_extensions].freeze
6
6
 
7
7
  def self.action_enabled?(action_name)
8
8
  RailsPgExtras.configuration.enabled_web_actions.include?(action_name.to_sym)
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,8 @@ elsif pg_version == "12"
13
13
  "5433"
14
14
  elsif pg_version == "13"
15
15
  "5434"
16
+ elsif pg_version == "14"
17
+ "5435"
16
18
  else
17
19
  "5432"
18
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-pg-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 4.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-12 00:00:00.000000000 Z
11
+ date: 2022-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-pg-extras
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.4.0
19
+ version: 4.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.4.0
26
+ version: 4.8.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement