rails-pg-extras-web 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/rails_pg_extras_web/application_controller.rb +1 -26
- data/app/controllers/rails_pg_extras_web/queries_controller.rb +41 -9
- data/app/views/layouts/rails_pg_extras_web/application.html.erb +1 -3
- data/app/views/rails_pg_extras_web/queries/index.html.erb +71 -9
- data/config/routes.rb +2 -2
- data/lib/rails_pg_extras_web/version.rb +1 -1
- metadata +5 -6
- data/app/views/rails_pg_extras_web/queries/run.html.erb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5530b516b0ab842d471eaed6b902a6448ebf482b5851c7f9b3e8ebb3ca9e7b9e
|
4
|
+
data.tar.gz: 7e0c1e7937d70ecd82fdecc39c601d4f6c3db59e7ca2303524539ac65b4bb302
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f6b6b7e5027069883fc23e385ba8b5bdc74378eba10e702c95b3b975f09e4acea9639abee99e48c3dcc737f636aee8b014ad4070ceb3da98bab1a6f37c9bfc1
|
7
|
+
data.tar.gz: 9387a5b9637197e5142c0c7c4bc8118d137ca05dd63a2cf9c580e2f93a9b6009725ac2f57ac0a4c6a63cd8105a767c38f64308e85be211b392d299379fcb8157
|
@@ -5,32 +5,7 @@ module RailsPgExtrasWeb
|
|
5
5
|
layout "rails_pg_extras_web/application"
|
6
6
|
|
7
7
|
if Rails.env.production? && ENV['PG_EXTRAS_USER'].present? && ENV['PG_EXTRAS_PASSWORD'].present?
|
8
|
-
http_basic_authenticate_with name: ENV['PG_EXTRAS_USER'], password: ENV['
|
9
|
-
end
|
10
|
-
|
11
|
-
protect_from_forgery with: :exception
|
12
|
-
|
13
|
-
helper_method :pg_stats_statements_enabled?
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def load_queries
|
18
|
-
@all_queries = {}
|
19
|
-
|
20
|
-
::RailsPGExtras::QUERIES.each do |query_name|
|
21
|
-
@all_queries[query_name] = {
|
22
|
-
disabled: query_disabled?(query_name),
|
23
|
-
command: query_name == :kill_all
|
24
|
-
}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def query_disabled?(query_name)
|
29
|
-
query_name.in?([:calls, :outliers]) && !pg_stats_statements_enabled?
|
30
|
-
end
|
31
|
-
|
32
|
-
def pg_stats_statements_enabled?
|
33
|
-
ActiveRecord::Base.connection.extensions.include?("pg_stat_statements")
|
8
|
+
http_basic_authenticate_with name: ENV['PG_EXTRAS_USER'], password: ENV['PG_EXTRAS_PASSWORD']
|
34
9
|
end
|
35
10
|
end
|
36
11
|
end
|
@@ -1,19 +1,51 @@
|
|
1
1
|
module RailsPgExtrasWeb
|
2
2
|
class QueriesController < ApplicationController
|
3
|
+
REQUIRED_EXTENSIONS = {
|
4
|
+
pg_stat_statements: %i[calls outliers],
|
5
|
+
pg_buffercache: %i[buffercache_stats buffercache_usage]
|
6
|
+
}
|
7
|
+
|
3
8
|
before_action :load_queries
|
9
|
+
helper_method :unavailable_extensions
|
10
|
+
|
11
|
+
def index
|
12
|
+
@query_name = params[:query_name]&.to_sym.presence_in(@all_queries.keys)
|
13
|
+
return unless @query_name
|
14
|
+
|
15
|
+
@result = RailsPGExtras.run_query(query_name: @query_name.to_sym, in_format: :raw)
|
16
|
+
rescue ActiveRecord::StatementInvalid => e
|
17
|
+
@error = e.message
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
4
21
|
|
5
|
-
def
|
22
|
+
def load_queries
|
23
|
+
@all_queries = {}
|
6
24
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
25
|
+
::RailsPGExtras::QUERIES.each do |query_name|
|
26
|
+
@all_queries[query_name] = {
|
27
|
+
disabled: query_disabled?(query_name),
|
28
|
+
command: query_name == :kill_all
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def query_disabled?(query_name)
|
34
|
+
case query_name
|
35
|
+
when :calls, :outliers
|
36
|
+
unavailable_extensions.key?(:pg_stat_statements)
|
37
|
+
when :buffercache_stats, :buffercache_usage
|
38
|
+
unavailable_extensions.key?(:pg_buffercache)
|
14
39
|
else
|
15
|
-
|
40
|
+
false
|
16
41
|
end
|
17
42
|
end
|
43
|
+
|
44
|
+
def unavailable_extensions
|
45
|
+
return @unavailable_extensions if defined?(@unavailable_extensions)
|
46
|
+
|
47
|
+
extensions = ActiveRecord::Base.connection.extensions
|
48
|
+
@unavailable_extensions = REQUIRED_EXTENSIONS.select { |extension, _| !extensions.include?(extension.to_s) }
|
49
|
+
end
|
18
50
|
end
|
19
51
|
end
|
@@ -2,11 +2,9 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>PG::Extras</title>
|
5
|
-
<%= csrf_meta_tags %>
|
6
|
-
<%= csp_meta_tag %>
|
7
5
|
</head>
|
8
6
|
<body onload="document.forms.queries.query_name.focus()">
|
9
|
-
<%= form_with url:
|
7
|
+
<%= form_with url: queries_path, id: "queries", method: :get do |f| %>
|
10
8
|
<%= f.select :query_name, options_for_select(@all_queries.except(:kill_all, :mandelbrot), params[:query_name]),
|
11
9
|
prompt: "--- select query ---"
|
12
10
|
%>
|
@@ -1,10 +1,72 @@
|
|
1
|
-
<%
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
<% if unavailable_extensions.any? && !@result %>
|
2
|
+
<% unavailable_extensions.each do |extension, queries| %>
|
3
|
+
<span style='color: orange'>
|
4
|
+
WARNING: Queries <%= queries.map { |q| "<b><u>#{q}</u></b>" }.join(", ").html_safe %> require extension: <b><%= extension %></b>
|
5
|
+
</span>
|
6
|
+
|
7
|
+
<h4>Rails</h4>
|
8
|
+
<pre style='background-color: #e2e2e2; padding: 10px'>ActiveRecord::Base.connection.enable_extension "<%= extension %>"</pre>
|
9
|
+
<h4>SQL</h4>
|
10
|
+
<pre style='background-color: #e2e2e2; padding: 10px'>CREATE EXTENSION <%= extension %></pre>
|
11
|
+
<% end %>
|
10
12
|
<% end %>
|
13
|
+
|
14
|
+
<% if @error %>
|
15
|
+
<span style='color: red'><%= @error %></span>
|
16
|
+
<% else %>
|
17
|
+
<% if @result && @result.any? %>
|
18
|
+
<table>
|
19
|
+
<caption><%= RubyPGExtras.description_for(query_name: @query_name) %></caption>
|
20
|
+
<thead>
|
21
|
+
<tr>
|
22
|
+
<% @result[0].keys.each do |header| %>
|
23
|
+
<th><%= header %></th>
|
24
|
+
<% end %>
|
25
|
+
</tr>
|
26
|
+
</thead>
|
27
|
+
<tbody>
|
28
|
+
<% @result.values.each do |row| %>
|
29
|
+
<tr>
|
30
|
+
<% row.each do |column| %>
|
31
|
+
<td><%= column %></td>
|
32
|
+
<% end %>
|
33
|
+
</tr>
|
34
|
+
<% end %>
|
35
|
+
</tbody>
|
36
|
+
</table>
|
37
|
+
|
38
|
+
<pre>run_at: <%= Time.now.utc %></pre>
|
39
|
+
<% else %>
|
40
|
+
<pre>No results</pre>
|
41
|
+
<% end %>
|
42
|
+
<% end %>
|
43
|
+
|
44
|
+
<style media="screen">
|
45
|
+
table {
|
46
|
+
font-family: monospace;
|
47
|
+
border-collapse: collapse;
|
48
|
+
width: 100%;
|
49
|
+
}
|
50
|
+
|
51
|
+
table th {
|
52
|
+
background-color: #c9c9;
|
53
|
+
}
|
54
|
+
|
55
|
+
table th, table td {
|
56
|
+
text-align: left;
|
57
|
+
border: 1px solid #c9c9;
|
58
|
+
padding: 3px;
|
59
|
+
}
|
60
|
+
|
61
|
+
table td {
|
62
|
+
overflow: hidden;
|
63
|
+
text-overflow: ellipsis;
|
64
|
+
white-space: nowrap;
|
65
|
+
}
|
66
|
+
|
67
|
+
table caption {
|
68
|
+
padding: 5px;
|
69
|
+
font-size: 15px;
|
70
|
+
font-weight: bold;
|
71
|
+
}
|
72
|
+
</style>
|
data/config/routes.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-pg-extras-web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Mazur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '2.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '2.0'
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
- tomasz.mazur@hey.com
|
@@ -52,7 +52,6 @@ files:
|
|
52
52
|
- app/controllers/rails_pg_extras_web/queries_controller.rb
|
53
53
|
- app/views/layouts/rails_pg_extras_web/application.html.erb
|
54
54
|
- app/views/rails_pg_extras_web/queries/index.html.erb
|
55
|
-
- app/views/rails_pg_extras_web/queries/run.html.erb
|
56
55
|
- config/routes.rb
|
57
56
|
- lib/rails-pg-extras-web.rb
|
58
57
|
- lib/rails_pg_extras_web/engine.rb
|
@@ -76,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
75
|
- !ruby/object:Gem::Version
|
77
76
|
version: '0'
|
78
77
|
requirements: []
|
79
|
-
rubygems_version: 3.1.
|
78
|
+
rubygems_version: 3.1.6
|
80
79
|
signing_key:
|
81
80
|
specification_version: 4
|
82
81
|
summary: Web UI for rails-pg-extras
|
@@ -1,59 +0,0 @@
|
|
1
|
-
<% if @error %>
|
2
|
-
<span style='color: red'><%= @error %></span>
|
3
|
-
<% else %>
|
4
|
-
<% if @result && @result.any? %>
|
5
|
-
<table>
|
6
|
-
<caption><%= RubyPGExtras.description_for(query_name: @query_name) %></caption>
|
7
|
-
<thead>
|
8
|
-
<tr>
|
9
|
-
<% @result[0].keys.each do |header| %>
|
10
|
-
<th><%= header %></th>
|
11
|
-
<% end %>
|
12
|
-
</tr>
|
13
|
-
</thead>
|
14
|
-
<tbody>
|
15
|
-
<% @result.values.each do |row| %>
|
16
|
-
<tr>
|
17
|
-
<% row.each do |column| %>
|
18
|
-
<td><%= column %></td>
|
19
|
-
<% end %>
|
20
|
-
</tr>
|
21
|
-
<% end %>
|
22
|
-
</tbody>
|
23
|
-
</table>
|
24
|
-
|
25
|
-
<pre>run_at: <%= Time.now.utc %></pre>
|
26
|
-
<% else %>
|
27
|
-
<pre>No results</pre>
|
28
|
-
<% end %>
|
29
|
-
<% end %>
|
30
|
-
|
31
|
-
<style media="screen">
|
32
|
-
table {
|
33
|
-
font-family: monospace;
|
34
|
-
border-collapse: collapse;
|
35
|
-
width: 100%;
|
36
|
-
}
|
37
|
-
|
38
|
-
table th {
|
39
|
-
background-color: #c9c9;
|
40
|
-
}
|
41
|
-
|
42
|
-
table th, table td {
|
43
|
-
text-align: left;
|
44
|
-
border: 1px solid #c9c9;
|
45
|
-
padding: 3px;
|
46
|
-
}
|
47
|
-
|
48
|
-
table td {
|
49
|
-
overflow: hidden;
|
50
|
-
text-overflow: ellipsis;
|
51
|
-
white-space: nowrap;
|
52
|
-
}
|
53
|
-
|
54
|
-
table caption {
|
55
|
-
padding: 5px;
|
56
|
-
font-size: 15px;
|
57
|
-
font-weight: bold;
|
58
|
-
}
|
59
|
-
</style>
|