rails-pg-extras 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/app/controllers/rails_pg_extras/web/actions_controller.rb +8 -0
- data/app/views/rails_pg_extras/web/queries/_unavailable_extensions_warning.html.erb +7 -5
- data/app/views/rails_pg_extras/web/queries/index.html.erb +17 -13
- data/lib/rails_pg_extras/configuration.rb +27 -0
- data/lib/rails_pg_extras/tasks/all.rake +1 -1
- data/lib/rails_pg_extras/version.rb +1 -1
- data/lib/rails_pg_extras/web.rb +5 -0
- data/lib/rails_pg_extras.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a246db60fafffa7ad4ea212b8357332d4172a58963c7f919a27ecbe75bf8e1ec
|
4
|
+
data.tar.gz: c2c5eab77af273048b3cd55a20ea675e78a78d19c6192eefdb87018278756660
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3a8c40da52f09d8f2a8f77f05561e39d069b43a86986029e907bec04933868e64211554a7d342156a902a31357119cef76ec6e33bb2d5c71d4847a6a7be0d56
|
7
|
+
data.tar.gz: e660e4dad9b7a0b95f796e648521210d302edc16aff16e582f1c548cb408b7ab4a17ef00e4c016ae4fcfbfeae3e7c0a1bd261793af43c4383bb09abdcc71b361
|
data/README.md
CHANGED
@@ -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)
|
@@ -5,9 +5,11 @@
|
|
5
5
|
<% end %>
|
6
6
|
</div>
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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 %>
|
@@ -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
|
@@ -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
|
data/lib/rails_pg_extras/web.rb
CHANGED
@@ -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/lib/rails_pg_extras.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-pg-extras
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.
|
19
|
+
version: 4.2.0
|
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.
|
26
|
+
version: 4.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- config/routes.rb
|
95
95
|
- docker-compose.yml.sample
|
96
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
|