rails-pg-extras 5.2.1 → 5.3.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: 4bd83f21b85de2b816dc334b72ad1bd0dfcb0f13ea6946fec42ebb93f47ba876
4
- data.tar.gz: 4e9e5b00cc7e07cf3baa1bc3e224fe8ab50510afa909b47e753873fb1e7a11e7
3
+ metadata.gz: 6b65d13da46887feb4613989005880cccc3f364409196d3e243e2fa741c778f0
4
+ data.tar.gz: 32af66da2e162cc33886c843cd5a9eccf73927557db042de874d4069aa4245a2
5
5
  SHA512:
6
- metadata.gz: 1a30823d47f9e0cab719b7ee6e750da28c751f4dc20d21756f7f3a633c07dd6390397e09502300cfcf9185184a9e00af83de40f2fd9b12a6319a6ade31ccb26f
7
- data.tar.gz: f01d58920638949122f26a74857cdab232168b274aee2d28d180eed09ea60a48ace036aa3ba772dc8ce41893d6e4a4397255167bc5ccf699a181c7205438ed93
6
+ metadata.gz: a38495774e883472f92b4c0782de90c2475247fbdc061f4d8c5e3fd10b034429832ac6de09cb214f8af375c70286e83f94eb15af4487319779b8599628122d7f
7
+ data.tar.gz: a6e32c538a51e26647a4373759015dd635c0659e28ad603a4ee1bb80619a450ab8f78b60d54707c487a147767d7d4811cd09808f7aec8e136ce37277a13284ca
@@ -0,0 +1,128 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby-version: ['3.2', '3.1', '3.0', '2.7', '2.6']
16
+ steps:
17
+ - uses: actions/checkout@v3
18
+ - name: Run PostgreSQL 11
19
+ run: |
20
+ docker run --env POSTGRES_USER=postgres \
21
+ --env POSTGRES_DB=rails-pg-extras-test \
22
+ --env POSTGRES_PASSWORD=secret \
23
+ -d -p 5432:5432 postgres:11.18-alpine \
24
+ postgres -c shared_preload_libraries=pg_stat_statements
25
+ - name: Run PostgreSQL 12
26
+ run: |
27
+ docker run --env POSTGRES_USER=postgres \
28
+ --env POSTGRES_DB=rails-pg-extras-test \
29
+ --env POSTGRES_PASSWORD=secret \
30
+ -d -p 5433:5432 postgres:12.13-alpine \
31
+ postgres -c shared_preload_libraries=pg_stat_statements
32
+ - name: Run PostgreSQL 13
33
+ run: |
34
+ docker run --env POSTGRES_USER=postgres \
35
+ --env POSTGRES_DB=rails-pg-extras-test \
36
+ --env POSTGRES_PASSWORD=secret \
37
+ -d -p 5434:5432 postgres:13.9-alpine \
38
+ postgres -c shared_preload_libraries=pg_stat_statements
39
+ - name: Run PostgreSQL 14
40
+ run: |
41
+ docker run --env POSTGRES_USER=postgres \
42
+ --env POSTGRES_DB=rails-pg-extras-test \
43
+ --env POSTGRES_PASSWORD=secret \
44
+ -d -p 5435:5432 postgres:14.6-alpine \
45
+ postgres -c shared_preload_libraries=pg_stat_statements
46
+ - name: Run PostgreSQL 15
47
+ run: |
48
+ docker run --env POSTGRES_USER=postgres \
49
+ --env POSTGRES_DB=rails-pg-extras-test \
50
+ --env POSTGRES_PASSWORD=secret \
51
+ -d -p 5436:5432 postgres:15.1-alpine \
52
+ postgres -c shared_preload_libraries=pg_stat_statements
53
+ sleep 15
54
+ - name: Set up Ruby ${{ matrix.ruby-version }}
55
+ uses: ruby/setup-ruby@v1
56
+ with:
57
+ ruby-version: ${{ matrix.ruby-version }}
58
+ - name: Setup dependencies
59
+ run: |
60
+ gem update --system
61
+ gem install bundler
62
+ sudo apt-get update --allow-releaseinfo-change
63
+ sudo apt install postgresql-client
64
+ sudo apt install libpq-dev
65
+ bundle config set --local path 'vendor/bundle'
66
+ bundle install
67
+ sleep 10
68
+ - name: Run tests for PG 11
69
+ env:
70
+ PG_VERSION: 11
71
+ POSTGRES_HOST: localhost
72
+ POSTGRES_USER: postgres
73
+ POSTGRES_DB: rails-pg-extras-test
74
+ POSTGRES_PASSWORD: secret
75
+ DATABASE_URL: postgresql://postgres:secret@localhost:5432/rails-pg-extras-test
76
+ run: |
77
+ bundle exec rspec spec/
78
+ - name: Run tests for PG 11
79
+ env:
80
+ PG_VERSION: 11
81
+ POSTGRES_HOST: localhost
82
+ POSTGRES_USER: postgres
83
+ POSTGRES_DB: rails-pg-extras-test
84
+ POSTGRES_PASSWORD: secret
85
+ DATABASE_URL: postgresql://postgres:secret@localhost:5432/rails-pg-extras-test
86
+ run: |
87
+ bundle exec rspec spec/
88
+ - name: Run tests for PG 12
89
+ env:
90
+ PG_VERSION: 12
91
+ POSTGRES_HOST: localhost
92
+ POSTGRES_USER: postgres
93
+ POSTGRES_DB: rails-pg-extras-test
94
+ POSTGRES_PASSWORD: secret
95
+ DATABASE_URL: postgresql://postgres:secret@localhost:5433/rails-pg-extras-test
96
+ run: |
97
+ bundle exec rspec spec/
98
+ - name: Run tests for PG 13
99
+ env:
100
+ PG_VERSION: 13
101
+ POSTGRES_HOST: localhost
102
+ POSTGRES_USER: postgres
103
+ POSTGRES_DB: rails-pg-extras-test
104
+ POSTGRES_PASSWORD: secret
105
+ DATABASE_URL: postgresql://postgres:secret@localhost:5434/rails-pg-extras-test
106
+ run: |
107
+ bundle exec rspec spec/
108
+ - name: Run tests for PG 14
109
+ env:
110
+ PG_VERSION: 14
111
+ POSTGRES_HOST: localhost
112
+ POSTGRES_USER: postgres
113
+ POSTGRES_DB: rails-pg-extras-test
114
+ POSTGRES_PASSWORD: secret
115
+ DATABASE_URL: postgresql://postgres:secret@localhost:5435/rails-pg-extras-test
116
+ run: |
117
+ bundle exec rspec spec/
118
+ - name: Run tests for PG 15
119
+ env:
120
+ PG_VERSION: 15
121
+ POSTGRES_HOST: localhost
122
+ POSTGRES_USER: postgres
123
+ POSTGRES_DB: rails-pg-extras-test
124
+ POSTGRES_PASSWORD: secret
125
+ DATABASE_URL: postgresql://postgres:secret@localhost:5436/rails-pg-extras-test
126
+ run: |
127
+ bundle exec rspec spec/
128
+
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rails PG Extras [![Gem Version](https://badge.fury.io/rb/rails-pg-extras.svg)](https://badge.fury.io/rb/rails-pg-extras) [![CircleCI](https://circleci.com/gh/pawurb/rails-pg-extras.svg?style=svg)](https://circleci.com/gh/pawurb/rails-pg-extras)
1
+ # Rails PG Extras [![Gem Version](https://badge.fury.io/rb/rails-pg-extras.svg)](https://badge.fury.io/rb/rails-pg-extras) [![GH Actions](https://github.com/pawurb/rails-pg-extras/actions/workflows/ci.yml/badge.svg)](https://github.com/pawurb/rails-pg-extras/actions)
2
2
 
3
3
  Rails port of [Heroku PG Extras](https://github.com/heroku/heroku-pg-extras) with several additions and improvements. The goal of this project is to provide powerful insights into the PostgreSQL database for Ruby on Rails apps that are not using the Heroku PostgreSQL plugin.
4
4
 
@@ -10,7 +10,7 @@ You can read this blog post for detailed step by step tutorial on how to [optimi
10
10
 
11
11
  Optionally you can enable a visual interface:
12
12
 
13
- ![Web interface](https://github.com/pawurb/rails-pg-extras/raw/master/pg-extras-ui.png)
13
+ ![Web interface](https://github.com/pawurb/rails-pg-extras/raw/main/pg-extras-ui.png)
14
14
 
15
15
  Alternative versions:
16
16
 
@@ -51,7 +51,7 @@ You should see the similar line in the output:
51
51
  RailsPgExtras.add_extensions
52
52
  ```
53
53
 
54
- By deafult a primary ActiveRecord database connection is used for running metadata queries, rake tasks and web UI. To connect to a different database you can specify an `ENV['RAILS_PG_EXTRAS_DATABASE_URL']` value in the following format:
54
+ By default a primary ActiveRecord database connection is used for running metadata queries, rake tasks and web UI. To connect to a different database you can specify an `ENV['RAILS_PG_EXTRAS_DATABASE_URL']` value in the following format:
55
55
 
56
56
  ```ruby
57
57
  ENV["RAILS_PG_EXTRAS_DATABASE_URL"] = "postgresql://postgres:secret@localhost:5432/database_name"
@@ -103,6 +103,12 @@ RailsPgExtras.long_running_queries(args: { threshold: "200 milliseconds" })
103
103
 
104
104
  ```
105
105
 
106
+ By default, queries target the `public` schema of the database. You can specify a different schema by passing the `schema` argument:
107
+
108
+ ```ruby
109
+ RailsPgExtras.table_cache_hit(args: { schema: "my_schema" })
110
+ ```
111
+
106
112
  ## Diagnose report
107
113
 
108
114
  The simplest way to start using pg-extras is to execute a `diagnose` method. It runs a set of checks and prints out a report highlighting areas that may require additional investigation:
@@ -113,7 +119,7 @@ RailsPgExtras.diagnose
113
119
  $ rake pg_extras:diagnose
114
120
  ```
115
121
 
116
- ![Diagnose report](https://github.com/pawurb/rails-pg-extras/raw/master/rails-pg-extras-diagnose.png)
122
+ ![Diagnose report](https://github.com/pawurb/rails-pg-extras/raw/main/rails-pg-extras-diagnose.png)
117
123
 
118
124
  Keep reading to learn about methods that `diagnose` uses under the hood.
119
125
 
@@ -152,18 +158,18 @@ RailsPgExtras.measure_queries { User.limit(10).map(&:team) }
152
158
  :queries=>
153
159
  {"SELECT \"users\".* FROM \"users\" LIMIT $1"=>
154
160
  {:count=>1,
155
- :total_duration=>3.452000004472211,
156
- :min_duration=>3.452000004472211,
157
- :max_duration=>3.452000004472211,
158
- :avg_duration=>3.452000004472211},
161
+ :total_duration=>1.9,
162
+ :min_duration=>1.9,
163
+ :max_duration=>1.9,
164
+ :avg_duration=>1.9},
159
165
  "SELECT \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" = $1 LIMIT $2"=>
160
166
  {:count=>10,
161
- :total_duration=>14.487000000372063,
162
- :min_duration=>0.778000001446344,
163
- :max_duration=>1.985000002605375,
164
- :avg_duration=>1.4487000000372063}},
165
- :total_duration=>24.812000003294088,
166
- :sql_duration=>17.939000004844274}
167
+ :total_duration=>0.94,
168
+ :min_duration=>0.62,
169
+ :max_duration=>1.37,
170
+ :avg_duration=>0.94}},
171
+ :total_duration=>13.35,
172
+ :sql_duration=>11.34}
167
173
 
168
174
  RailsPgExtras.measure_queries { User.limit(10).includes(:team).map(&:team) }
169
175
 
@@ -171,21 +177,36 @@ RailsPgExtras.measure_queries { User.limit(10).includes(:team).map(&:team) }
171
177
  :queries=>
172
178
  {"SELECT \"users\".* FROM \"users\" LIMIT $1"=>
173
179
  {:count=>1,
174
- :total_duration=>3.7079999965499155,
175
- :min_duration=>3.7079999965499155,
176
- :max_duration=>3.7079999965499155,
177
- :avg_duration=>3.7079999965499155},
180
+ :total_duration=>3.43,
181
+ :min_duration=>3.43,
182
+ :max_duration=>3.43,
183
+ :avg_duration=>3.43},
178
184
  "SELECT \"teams\".* FROM \"teams\" WHERE \"teams\".\"id\" IN ($1, $2, $3, $4, $5, $6, $7, $8)"=>
179
185
  {:count=>1,
180
- :total_duration=>2.422000005026348,
181
- :min_duration=>2.422000005026348,
182
- :max_duration=>2.422000005026348,
183
- :avg_duration=>2.422000005026348}},
184
- :total_duration=>9.905999999318738,
185
- :sql_duration=>6.1300000015762635}
186
+ :total_duration=>2.59,
187
+ :min_duration=>2.59,
188
+ :max_duration=>2.59,
189
+ :avg_duration=>2.59}},
190
+ :total_duration=>9.75,
191
+ :sql_duration=>6.02}
192
+
193
+ ```
194
+
195
+ Optionally, by including [Marginalia gem](https://github.com/basecamp/marginalia) and configuring it to display query backtraces:
196
+
197
+ `config/development.rb`
198
+
199
+ ```ruby
200
+
201
+ Marginalia::Comment.components = [:line]
186
202
 
187
203
  ```
188
204
 
205
+ you can add this info to the output:
206
+
207
+ ![Marginalia logs](https://github.com/pawurb/rails-pg-extras/raw/main/marginalia-logs.png)
208
+
209
+
189
210
  ### `table_info`
190
211
 
191
212
  This method displays metadata metrics for all or a selected table. You can use it to check the table's size, its cache hit metrics, and whether it is correctly indexed. Many sequential scans or no index scans are potential indicators of misconfigured indexes. This method aggregates data provided by other methods in an easy to analyze summary format.
@@ -446,18 +467,18 @@ This command displays the total size of all indexes on the database, in MB. It i
446
467
  RailsPgExtras.index_size
447
468
 
448
469
  $ rake pg_extras:index_size
449
- name | size
450
- ---------------------------------------------------------------+---------
451
- idx_activity_attemptable_and_type_lesson_enrollment | 5196 MB
452
- index_enrollment_attemptables_by_attempt_and_last_in_group | 4045 MB
453
- index_attempts_on_student_id | 2611 MB
454
- enrollment_activity_attemptables_pkey | 2513 MB
455
- index_attempts_on_student_id_final_attemptable_type | 2466 MB
456
- attempts_pkey | 2466 MB
457
- index_attempts_on_response_id | 2404 MB
458
- index_attempts_on_enrollment_id | 1957 MB
459
- index_enrollment_attemptables_by_enrollment_activity_id | 1789 MB
460
- enrollment_activities_pkey | 458 MB
470
+ name | size | schema |
471
+ ---------------------------------------------------------------+-------------------
472
+ idx_activity_attemptable_and_type_lesson_enrollment | 5196 MB | public |
473
+ index_enrollment_attemptables_by_attempt_and_last_in_group | 4045 MB | public |
474
+ index_attempts_on_student_id | 2611 MB | public |
475
+ enrollment_activity_attemptables_pkey | 2513 MB | custom |
476
+ index_attempts_on_student_id_final_attemptable_type | 2466 MB | custom |
477
+ attempts_pkey | 2466 MB | custom |
478
+ index_attempts_on_response_id | 2404 MB | public |
479
+ index_attempts_on_enrollment_id | 1957 MB | public |
480
+ index_enrollment_attemptables_by_enrollment_activity_id | 1789 MB | public |
481
+ enrollment_activities_pkey | 458 MB | public |
461
482
  (truncated results for brevity)
462
483
  ```
463
484
 
@@ -470,13 +491,13 @@ RailsPgExtras.table_size
470
491
 
471
492
  $ rake pg_extras:table_size
472
493
 
473
- name | size
474
- ---------------------------------------------------------------+---------
475
- learning_coaches | 196 MB
476
- states | 145 MB
477
- grade_levels | 111 MB
478
- charities_customers | 73 MB
479
- charities | 66 MB
494
+ name | size | schema |
495
+ ---------------------------------------------------------------+-------------------
496
+ learning_coaches | 196 MB | public |
497
+ states | 145 MB | public |
498
+ grade_levels | 111 MB | custom |
499
+ charities_customers | 73 MB | custom |
500
+ charities | 66 MB | public |
480
501
  (truncated results for brevity)
481
502
  ```
482
503
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPgExtras
4
- VERSION = "5.2.1"
4
+ VERSION = "5.3.0"
5
5
  end
Binary file
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: 5.2.1
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-01 00:00:00.000000000 Z
11
+ date: 2023-08-25 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: 5.2.1
19
+ version: 5.3.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: 5.2.1
26
+ version: 5.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -75,7 +75,7 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - ".circleci/config.yml"
78
+ - ".github/workflows/ci.yml"
79
79
  - ".gitignore"
80
80
  - Gemfile
81
81
  - LICENSE.txt
@@ -106,6 +106,7 @@ files:
106
106
  - lib/rails_pg_extras/version.rb
107
107
  - lib/rails_pg_extras/web.rb
108
108
  - lib/rails_pg_extras/web/engine.rb
109
+ - marginalia-logs.png
109
110
  - pg-extras-ui.png
110
111
  - rails-pg-extras-diagnose.png
111
112
  - rails-pg-extras.gemspec
data/.circleci/config.yml DELETED
@@ -1,71 +0,0 @@
1
- version: 2
2
- jobs:
3
- test:
4
- docker:
5
- - image: cimg/ruby:2.7.6
6
- environment:
7
- DATABASE_URL: postgresql://postgres:secret@localhost:5432/rails-pg-extras-test
8
- - image: cimg/postgres:11.15
9
- command: postgres -c shared_preload_libraries=pg_stat_statements
10
- name: postgres11
11
- environment:
12
- POSTGRES_USER: postgres
13
- POSTGRES_DB: rails-pg-extras-test
14
- POSTGRES_PASSWORD: secret
15
- - image: cimg/postgres:12.10
16
- command: postgres -c shared_preload_libraries=pg_stat_statements
17
- name: postgres12
18
- environment:
19
- POSTGRES_USER: postgres
20
- POSTGRES_DB: rails-pg-extras-test
21
- POSTGRES_PASSWORD: secret
22
- - image: cimg/postgres:13.6
23
- command: postgres -c shared_preload_libraries=pg_stat_statements
24
- name: postgres13
25
- environment:
26
- POSTGRES_USER: postgres
27
- POSTGRES_DB: rails-pg-extras-test
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
36
- parallelism: 1
37
- steps:
38
- - checkout
39
- - run: gem update --system
40
- - run: gem install bundler
41
- - run: sudo apt-get update --allow-releaseinfo-change
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
46
- - run: dockerize -wait tcp://postgres11:5432 -timeout 1m
47
- - run:
48
- name: Run specs for PG 11
49
- environment:
50
- DATABASE_URL: postgresql://postgres:secret@postgres11:5432/rails-pg-extras-test
51
- command: bundle exec rspec spec/
52
- - run:
53
- name: Run specs for PG 12
54
- environment:
55
- DATABASE_URL: postgresql://postgres:secret@postgres12:5432/rails-pg-extras-test
56
- command: bundle exec rspec spec/
57
- - run:
58
- name: Run specs for PG 13
59
- environment:
60
- DATABASE_URL: postgresql://postgres:secret@postgres13:5432/rails-pg-extras-test
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/
67
- workflows:
68
- version: 2
69
- test:
70
- jobs:
71
- - test