rails-pg-extras-web 2.2.0 → 3.1.0

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: a2a3e9fef31d95866c584c87bb8f01cc3f150f086500b01d0dbb05ebfc6d9533
4
- data.tar.gz: 7d1974687a38bd6792dab2aeacaeec4375e391052bb029c5dfd8dfc66f303085
3
+ metadata.gz: 8ca457b8f7491e7b1eab0a053ec0fd563db431209718b40203a121dc31ecf453
4
+ data.tar.gz: aa628d82e9b6858f565ea0b6fbb57c4c945706e684ba9c9e85530bbaf728fa69
5
5
  SHA512:
6
- metadata.gz: 92f4793d25c4edaf1943daa7cb36af925b74ce9219ee7c87e410959d902ea2b0291b533011468c4f7e4bf68409af2c121e2288216cb3cfcc656ff292a3c24235
7
- data.tar.gz: 249851bc75a35aa16f904e998ac96d461e8f01b8ab6c875b6c15414b8af0bd808e6b7520e97835f2801b46e458b8c16bd0e1000d2683db0238d99dcfb552090e
6
+ metadata.gz: 70c68e56d0f99bb4511b23ac98d246e381e67634b751f02b6c6e57906ca8efd9a6c07861c75cb15a043fb8654d89c1a991ec9288b1cd07a087e9eefcbc45eecd
7
+ data.tar.gz: d9d877137d79912412c3d7885e8b49bdf1d4a3ad0024d37908f99dc4567de864ab963359ee9158288a2ece7b82e6444d78cd9eb7c1a9468a4467578522b3e12b
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # RailsPgExtrasWeb
2
2
  Web UI for [rails-pg-extras](https://github.com/pawurb/rails-pg-extras)
3
3
 
4
+ ![WebUI](https://raw.githubusercontent.com/pawurb/rails-pg-extras/master/rails-pg-extras-web.png)
5
+
4
6
  ## Installation
5
7
  Add this line to your application's Gemfile:
6
8
 
@@ -0,0 +1,26 @@
1
+ module RailsPgExtrasWeb
2
+ class ActionsController < ApplicationController
3
+ def kill_all
4
+ run(:kill_all)
5
+ end
6
+
7
+ def pg_stat_statements_reset
8
+ run(:pg_stat_statements_reset)
9
+ end
10
+
11
+ def add_extensions
12
+ run(:add_extensions)
13
+ end
14
+
15
+ private
16
+
17
+ def run(action)
18
+ begin
19
+ RailsPGExtras.run_query(query_name: action, in_format: :raw)
20
+ redirect_to root_path, notice: "Successfully ran #{action}"
21
+ rescue ActiveRecord::StatementInvalid => e
22
+ redirect_to root_path, alert: "Error: #{e.message}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,9 +1,18 @@
1
1
  require "rails-pg-extras"
2
+ require "rails-pg-extras/version"
2
3
 
3
4
  module RailsPgExtrasWeb
4
5
  class ApplicationController < ActionController::Base
5
6
  layout "rails_pg_extras_web/application"
6
7
 
8
+ REQUIRED_EXTENSIONS = {
9
+ pg_stat_statements: %i[calls outliers pg_stat_statements_reset],
10
+ pg_buffercache: %i[buffercache_stats buffercache_usage],
11
+ sslinfo: %i[ssl_used]
12
+ }
13
+
14
+ ACTIONS = %i[kill_all pg_stat_statements_reset add_extensions]
15
+
7
16
  if Rails.env.production? && ENV['PG_EXTRAS_USER'].present? && ENV['PG_EXTRAS_PASSWORD'].present?
8
17
  http_basic_authenticate_with name: ENV['PG_EXTRAS_USER'], password: ENV['PG_EXTRAS_PASSWORD']
9
18
  end
@@ -1,11 +1,5 @@
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
- sslinfo: %i[ssl_used]
7
- }
8
-
9
3
  before_action :load_queries
10
4
  helper_method :unavailable_extensions
11
5
 
@@ -27,8 +21,8 @@ module RailsPgExtrasWeb
27
21
  private
28
22
 
29
23
  def load_queries
30
- @all_queries = RailsPGExtras::QUERIES.inject({}) do |memo, query_name|
31
- unless query_name.in? %i[kill_all mandelbrot]
24
+ @all_queries = (RailsPGExtras::QUERIES - ACTIONS).inject({}) do |memo, query_name|
25
+ unless query_name.in? %i[mandelbrot]
32
26
  memo[query_name] = { disabled: query_disabled?(query_name) }
33
27
  end
34
28
 
@@ -1,10 +1,26 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title><%= content_for :title %></title>
5
- <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
6
- </head>
7
- <body class="p-5 text-xs">
8
- <%= yield %>
9
- </body>
3
+ <head>
4
+ <title><%= content_for :title %> | v<%= RailsPGExtras::VERSION %></title>
5
+ <%= javascript_include_tag "https://unpkg.com/@rails/ujs" %>
6
+ <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body class="p-5 text-xs">
10
+ <% if flash[:notice] %>
11
+ <div class="bg-green-100 border-l-4 border-green-500 text-green-700 p-4 mb-4" role="alert">
12
+ <p class="font-bold">Notice</p>
13
+ <p><%= flash[:notice] %></p>
14
+ </div>
15
+ <% end %>
16
+
17
+ <% if flash[:alert] %>
18
+ <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-4" role="alert">
19
+ <p class="font-bold">Alert</p>
20
+ <p><%= flash[:alert] %></p>
21
+ </div>
22
+ <% end %>
23
+
24
+ <%= yield %>
25
+ </body>
10
26
  </html>
@@ -0,0 +1,9 @@
1
+ <h1 class="font-bold text-xl my-5">Diagnose</h1>
2
+ <table class="w-full font-mono border-collapse border my-5">
3
+ <% RailsPGExtras.diagnose(in_format: :hash).each do |diagnosis| %>
4
+ <tr class="<%= diagnosis[:ok] ? 'bg-green-300' : 'bg-red-300' %>">
5
+ <td class='p-1 border font-bold'><%= diagnosis[:check_name] %></td>
6
+ <td class='p-1 border'><%= diagnosis[:message] %></td>
7
+ </tr>
8
+ <% end %>
9
+ </table>
@@ -1,6 +1,6 @@
1
1
  <h1 class="font-bold text-xl my-5"><%= title %></h1>
2
2
 
3
- <table class="w-full font-mono border-collapse border border-green-800 my-5">
3
+ <table class="w-full font-mono border-collapse border my-5">
4
4
  <thead>
5
5
  <tr class="bg-gray-300">
6
6
  <% headers.each do |header| %>
@@ -18,5 +18,4 @@
18
18
  <% end %>
19
19
  </tbody>
20
20
  </table>
21
-
22
21
  <span class="italic">run_at: <%= Time.now.utc %></span>
@@ -5,44 +5,9 @@
5
5
  <% end %>
6
6
  </div>
7
7
 
8
-
9
- <span id="rails" class="font-mono font-bold p-3 bg-gray-100 cursor-pointer select-none">RAILS</span> <span id="sql" class="font-mono font-normal p-3 bg-gray-50 cursor-pointer select-none">SQL</span>
10
- <pre id="rails_code" class="font-mono p-5 bg-gray-100 block">
11
- <% unavailable_extensions.each do |extension, queries| %>
12
- ActiveRecord::Base.connection.enable_extension "<%= extension %>"
13
- <% end %>
14
- </pre>
15
-
16
- <pre id="sql_code" class="font-mono p-5 bg-gray-100 hidden">
17
- <% unavailable_extensions.each do |extension, queries| %>
18
- CREATE EXTENSION <%= extension %>;
19
- <% end %>
20
- </pre>
21
-
22
- <script>
23
- const rails = document.getElementById('rails')
24
- const sql = document.getElementById('sql')
25
- const railsCode = document.getElementById('rails_code')
26
- const sqlCode = document.getElementById('sql_code')
27
-
28
- rails.addEventListener('click', (e) => {
29
- railsCode.classList.remove('hidden')
30
- sqlCode.classList.add('hidden')
31
-
32
- rails.classList.replace('bg-gray-50','bg-gray-100')
33
- sql.classList.replace('bg-gray-100','bg-gray-50')
34
- rails.classList.replace('font-normal','font-bold')
35
- sql.classList.replace('font-bold','font-normal')
36
- })
37
-
38
- sql.addEventListener('click', (e) => {
39
- railsCode.classList.add('hidden')
40
- sqlCode.classList.remove('hidden')
41
-
42
- rails.classList.replace('bg-gray-100','bg-gray-50')
43
- sql.classList.replace('bg-gray-50','bg-gray-100')
44
- rails.classList.replace('font-bold','font-normal')
45
- sql.classList.replace('font-normal','font-bold')
46
- })
47
- </script>
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' %>
48
13
 
@@ -1,4 +1,21 @@
1
1
  <%= content_for :title, "pg_extras" %>
2
2
  <%= render "rails_pg_extras_web/shared/queries_selector" %>
3
-
4
3
  <%= render "unavailable_extensions_warning" if unavailable_extensions.any? %>
4
+ <%= render "diagnose" if unavailable_extensions.none? %>
5
+
6
+ <h1 class="font-bold text-xl my-5">Actions</h1>
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
+ %>
15
+
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
+ %>
@@ -2,7 +2,7 @@
2
2
  <%= render "rails_pg_extras_web/shared/queries_selector" %>
3
3
 
4
4
  <% if @error %>
5
- <span class="text-red"><%= @error %></span>
5
+ <div class="text-red-500 p-3 font-mono my-5"><%= @error %></div>
6
6
  <% else %>
7
7
  <% if @result&.any? %>
8
8
  <%= render "result",
data/config/routes.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  RailsPgExtrasWeb::Engine.routes.draw do
2
2
  resources :queries, only: [:index]
3
3
 
4
+ post "/actions/kill_all" => "actions#kill_all", as: :kill_all_action
5
+ post "/actions/pg_stat_statements_reset" => "actions#pg_stat_statements_reset", as: :pg_stat_statements_reset_action
6
+ post "/actions/add_extensions" => "actions#add_extensions", as: :add_extensions_action
7
+
4
8
  root to: "queries#index"
5
9
  end
@@ -1,3 +1,3 @@
1
1
  module RailsPgExtrasWeb
2
- VERSION = '2.2.0'
2
+ VERSION = '3.1.0'
3
3
  end
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: 2.2.0
4
+ version: 3.1.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-10-26 00:00:00.000000000 Z
11
+ date: 2021-10-30 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: '2.2'
33
+ version: '3.1'
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: '2.2'
40
+ version: '3.1'
41
41
  description:
42
42
  email:
43
43
  - tomasz.mazur@hey.com
@@ -48,9 +48,11 @@ files:
48
48
  - MIT-LICENSE
49
49
  - README.md
50
50
  - Rakefile
51
+ - app/controllers/rails_pg_extras_web/actions_controller.rb
51
52
  - app/controllers/rails_pg_extras_web/application_controller.rb
52
53
  - app/controllers/rails_pg_extras_web/queries_controller.rb
53
54
  - app/views/layouts/rails_pg_extras_web/application.html.erb
55
+ - app/views/rails_pg_extras_web/queries/_diagnose.html.erb
54
56
  - app/views/rails_pg_extras_web/queries/_result.html.erb
55
57
  - app/views/rails_pg_extras_web/queries/_unavailable_extensions_warning.html.erb
56
58
  - app/views/rails_pg_extras_web/queries/index.html.erb