rails-pg-extras 4.1.0 → 4.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6ae59243330e4542bce1091be0c9569e358136526ea8e3905f51926bc7e301a
4
- data.tar.gz: 3981ba3942d85a69bc808665df427fa4401754861707bc93176adc1ad03b49cf
3
+ metadata.gz: b60a814cc2ebe5c32cb7ad76cec4d2a0a69c3adb2808c96ec7bc32d257af04b2
4
+ data.tar.gz: 52d5e8786eb51f79b757b378110f0aa40bff85940222131ee689efa19429d927
5
5
  SHA512:
6
- metadata.gz: bffcc20a98ee3e0b7e127ef96f268500cf49fd3e30a009cf1d1ffbe88246524763f8b4c76df389969febf4d78d5b3c6bc51edacd18a2d5581b4ea86e314aa6a9
7
- data.tar.gz: 100bef0be5f9a22e90c81a37f75288e8833e9e7dccfccbaf88d0b0bb6870f49d083e5322e4705ae4961a2b8d085496e85a7e5253c2d57396c229194591cf62d7
6
+ metadata.gz: 9dd97240083d2b648f08d4b74dee3575cc58166ae3730044d24360c05d6537e14df2777c20a10253696012c2554502748467d68b61d4f62701d95b95452f5cd5
7
+ data.tar.gz: f2dc275df8cd32227f7b3c4b8d2d0f4b39fe3e4d86130a5d04197eeb579c057a8e7672a49dd3b62b7a0dc4ce43cc2c369b95dd1fb4522bfed3ae8d81823a9d18
data/README.md CHANGED
@@ -29,7 +29,7 @@ Alternative versions:
29
29
  In your Gemfile
30
30
 
31
31
  ```ruby
32
- gem "rails-pg-extras", require: "rails_pg_extras"
32
+ gem "rails-pg-extras"
33
33
  ```
34
34
 
35
35
  `calls` and `outliers` queries require [pg_stat_statements](https://www.postgresql.org/docs/current/pgstatstatements.html) extension.
@@ -121,6 +121,17 @@ You can enable UI using a Rails engine by adding the following code in `config/r
121
121
 
122
122
  You can enable HTTP basic auth by specifying `RAILS_PG_EXTRAS_USER` and `RAILS_PG_EXTRAS_PASSWORD` variables.
123
123
 
124
+ You can configure available web actions in `config/initializers/rails_pg_extras.rb`:
125
+
126
+ ```ruby
127
+ RailsPgExtras.configure do |config|
128
+ # Rails-pg-extras does not enable all the web actions by default. You can check all available actions via `RailsPgExtras::Web::ACTIONS`.
129
+ # For example, you may want to enable the dangerous `kill_all` action.
130
+
131
+ config.enabled_web_actions = %i[kill_all pg_stat_statements_reset enable_extensions]
132
+ end
133
+ ```
134
+
124
135
  ## Available methods
125
136
 
126
137
  ### `table_info`
@@ -1,5 +1,7 @@
1
1
  module RailsPgExtras::Web
2
2
  class ActionsController < RailsPgExtras::Web::ApplicationController
3
+ before_action :validate_action!
4
+
3
5
  def kill_all
4
6
  run(:kill_all)
5
7
  end
@@ -14,6 +16,12 @@ module RailsPgExtras::Web
14
16
 
15
17
  private
16
18
 
19
+ def validate_action!
20
+ unless RailsPgExtras::Web.action_enabled?(action_name)
21
+ render plain: "Action '#{action_name}' is not enabled!", status: :forbidden
22
+ end
23
+ end
24
+
17
25
  def run(action)
18
26
  begin
19
27
  RailsPgExtras.run_query(query_name: action, in_format: :raw)
@@ -1,4 +1,4 @@
1
- require "rails_pg_extras"
1
+ require "rails-pg-extras"
2
2
  require "rails_pg_extras/version"
3
3
 
4
4
  module RailsPgExtras::Web
@@ -5,9 +5,11 @@
5
5
  <% end %>
6
6
  </div>
7
7
 
8
- <%= link_to "Enable extensions", add_extensions_action_path,
9
- method: "post",
10
- data: {
11
- confirm: "This command will enable following extensions: #{unavailable_extensions.keys.join(', ')}. Do you want to proceeed?"
12
- }, class: 'border p-3 bg-green-500 text-white hover:bg-green-600 font-bold rounded' %>
8
+ <% if RailsPgExtras::Web.action_enabled?(:enable_extensions) %>
9
+ <%= link_to "Enable extensions", add_extensions_action_path,
10
+ method: "post",
11
+ data: {
12
+ confirm: "This command will enable following extensions: #{unavailable_extensions.keys.join(', ')}. Do you want to proceeed?"
13
+ }, class: 'border p-3 bg-green-500 text-white hover:bg-green-600 font-bold rounded' %>
14
+ <% end %>
13
15
 
@@ -5,17 +5,21 @@
5
5
 
6
6
  <h1 class="font-bold text-xl my-5">Actions</h1>
7
7
 
8
- <%= link_to "kill_all", kill_all_action_path,
9
- method: "post",
10
- data: {
11
- confirm: "This commands kills all the currently active connections to the database. Do you want to proceed?"
12
- },
13
- class: 'border p-3 bg-red-500 text-white hover:bg-red-600 font-bold rounded'
14
- %>
8
+ <% if RailsPgExtras::Web.action_enabled?(:kill_all) %>
9
+ <%= link_to "kill_all", kill_all_action_path,
10
+ method: "post",
11
+ data: {
12
+ confirm: "This commands kills all the currently active connections to the database. Do you want to proceed?"
13
+ },
14
+ class: 'border p-3 bg-red-500 text-white hover:bg-red-600 font-bold rounded'
15
+ %>
16
+ <% end %>
15
17
 
16
- <%= link_to "pg_stat_statements_reset", pg_stat_statements_reset_action_path,
17
- method: "post",
18
- data: {
19
- confirm: "This command discards all statistics gathered so far by pg_stat_statements. Do you want to proceed?"
20
- }, class: 'border p-3 bg-blue-500 text-white hover:bg-blue-600 font-bold rounded'
21
- %>
18
+ <% if RailsPgExtras::Web.action_enabled?(:pg_stat_statements_reset) %>
19
+ <%= link_to "pg_stat_statements_reset", pg_stat_statements_reset_action_path,
20
+ method: "post",
21
+ data: {
22
+ confirm: "This command discards all statistics gathered so far by pg_stat_statements. Do you want to proceed?"
23
+ }, class: 'border p-3 bg-blue-500 text-white hover:bg-blue-600 font-bold rounded'
24
+ %>
25
+ <% end %>
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'terminal-table'
4
- require 'ruby_pg_extras'
4
+ require 'ruby-pg-extras'
5
5
  require 'rails_pg_extras/diagnose_data'
6
6
  require 'rails_pg_extras/diagnose_print'
7
7
  require 'rails_pg_extras/index_info'
8
8
  require 'rails_pg_extras/index_info_print'
9
9
  require 'rails_pg_extras/table_info'
10
10
  require 'rails_pg_extras/table_info_print'
11
- require 'rails_pg_extras/web'
12
11
 
13
12
  module RailsPgExtras
14
13
  QUERIES = RubyPgExtras::QUERIES
@@ -96,4 +95,6 @@ module RailsPgExtras
96
95
  end
97
96
  end
98
97
 
98
+ require 'rails_pg_extras/web'
99
+ require 'rails_pg_extras/configuration'
99
100
  require 'rails_pg_extras/railtie' if defined?(Rails)
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_pg_extras/web"
4
+
5
+ module RailsPgExtras
6
+ class Configuration
7
+ DEFAULT_CONFIG = { enabled_web_actions: Web::ACTIONS - [:kill_all] }
8
+
9
+ attr_reader :enabled_web_actions
10
+
11
+ def initialize(attrs)
12
+ self.enabled_web_actions = attrs[:enabled_web_actions]
13
+ end
14
+
15
+ def enabled_web_actions=(*actions)
16
+ @enabled_web_actions = actions.flatten.map(&:to_sym)
17
+ end
18
+ end
19
+
20
+ def self.configuration
21
+ @configuration ||= Configuration.new(Configuration::DEFAULT_CONFIG)
22
+ end
23
+
24
+ def self.configure
25
+ yield(configuration)
26
+ end
27
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails_pg_extras'
3
+ require 'rails-pg-extras'
4
4
 
5
5
  namespace :pg_extras do
6
6
  task :establish_connection do
@@ -8,7 +8,7 @@ namespace :pg_extras do
8
8
  ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
9
9
  else
10
10
  db_config_file = File.read('config/database.yml')
11
- db_config = YAML::load(ERB.new(db_config_file).result)
11
+ db_config = YAML::load(ERB.new(db_config_file).result, aliases: true)
12
12
  ActiveRecord::Base.establish_connection(db_config[Rails.env])
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPgExtras
4
- VERSION = "4.1.0"
4
+ VERSION = "4.4.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,5 +2,10 @@ 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
6
+
7
+ def self.action_enabled?(action_name)
8
+ RailsPgExtras.configuration.enabled_web_actions.include?(action_name.to_sym)
9
+ end
5
10
  end
6
11
  end
data/spec/smoke_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
- require 'rails_pg_extras'
4
+ require 'rails-pg-extras'
5
5
 
6
6
  describe RailsPgExtras do
7
7
  RailsPgExtras::QUERIES.each do |query_name|
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'rubygems'
4
4
  require 'bundler/setup'
5
5
  require 'active_record'
6
- require_relative '../lib/rails_pg_extras'
6
+ require_relative '../lib/rails-pg-extras'
7
7
 
8
8
  pg_version = ENV["PG_VERSION"]
9
9
 
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.1.0
4
+ version: 4.4.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-03-16 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.1.0
19
+ version: 4.4.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.1.0
26
+ version: 4.4.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -93,7 +93,8 @@ files:
93
93
  - app/views/rails_pg_extras/web/shared/_queries_selector.html.erb
94
94
  - config/routes.rb
95
95
  - docker-compose.yml.sample
96
- - lib/rails_pg_extras.rb
96
+ - lib/rails-pg-extras.rb
97
+ - lib/rails_pg_extras/configuration.rb
97
98
  - lib/rails_pg_extras/diagnose_data.rb
98
99
  - lib/rails_pg_extras/diagnose_print.rb
99
100
  - lib/rails_pg_extras/index_info.rb