rails-pg-extras 1.6.0 → 2.0.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: b44baf89a4349ef720b371a8a83a8397e0e848794b1bf248398cfd19c5f606d5
4
- data.tar.gz: ebdabe9d275ed5ef7132ce604f894a42520226db0b1dc5d50acd092a0aed6dd4
3
+ metadata.gz: c107fe728b02513bceaa617c45f5cf5bc4048fb0376ec46a13a70ba86cff4cf9
4
+ data.tar.gz: 07fd71c6c2a1ff119b30845f32967d4d2c49d8ae0eccfbdaf52b228b5c907541
5
5
  SHA512:
6
- metadata.gz: d0b9e1505835974df1959e620385461f7c5c92838efadd18abb57a5656d1b942d8f097f7c70389e815a96a5dcb239b67b16cee430188e0532ccef57eb2a6ff50
7
- data.tar.gz: 269a9b8bb29c5114c43885d61f849b3ed73664cb7c5e9e772c85281cacebbce641b224fe0e246bda5a7ab5426210ee3a75a0ac0a36c6555abb64988d7b66b733
6
+ metadata.gz: d9de7a07381f8d203e60f98b750b0791e7be932dfaf8a621106bc69bbe44eb4ce5ca0893e4d8b22905913626f28bedc77da7fad282c4171ea51e3b424c359984
7
+ data.tar.gz: 99872d4b0efcddf6d4a0af106068fc2a83544053c13596c2532320ac746a3ca6174d7ff1fd8e3a8c2533b49acaeaac896bbf6def5bc1f5dc083e6956b9cf52f9
data/.circleci/config.yml CHANGED
@@ -6,6 +6,7 @@ jobs:
6
6
  environment:
7
7
  DATABASE_URL: postgresql://postgres:secret@localhost:5432/rails-pg-extras-test
8
8
  - image: circleci/postgres:11.5
9
+ command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200
9
10
  environment:
10
11
  POSTGRES_USER: postgres
11
12
  POSTGRES_DB: rails-pg-extras-test
data/README.md CHANGED
@@ -526,20 +526,20 @@ This commands kills all the currently active connections to the database. It can
526
526
 
527
527
  ### `buffercache_stats`
528
528
 
529
- This command shows the relations buffered in database share buffer, ordered by percentage taken. It also shows that how much of the whole relation is buffered.
530
-
531
529
  ```ruby
532
530
  RailsPGExtras.buffercache_stats(args: { limit: 10 })
533
531
  ```
534
532
 
535
- ### `buffercache_usage`
533
+ This command shows the relations buffered in database share buffer, ordered by percentage taken. It also shows that how much of the whole relation is buffered.
536
534
 
537
- This command calculates how many blocks from which table are currently cached.
535
+ ### `buffercache_usage`
538
536
 
539
537
  ```ruby
540
538
  RailsPGExtras.buffercache_usage(args: { limit: 20 })
541
539
  ```
542
540
 
541
+ This command calculates how many blocks from which table are currently cached.
542
+
543
543
  ### `extensions`
544
544
 
545
545
  ```ruby
@@ -1,12 +1,30 @@
1
1
  version: '3'
2
2
 
3
3
  services:
4
- postgres:
4
+ postgres11:
5
5
  image: postgres:11.5-alpine
6
+ command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200
6
7
  environment:
7
8
  POSTGRES_USER: postgres
8
9
  POSTGRES_DB: rails-pg-extras-test
9
10
  POSTGRES_PASSWORD: secret
10
11
  ports:
11
12
  - '5432:5432'
12
-
13
+ postgres12:
14
+ image: postgres:12.7-alpine
15
+ command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200
16
+ environment:
17
+ POSTGRES_USER: postgres
18
+ POSTGRES_DB: rails-pg-extras-test
19
+ POSTGRES_PASSWORD: secret
20
+ ports:
21
+ - '5433:5432'
22
+ postgres13:
23
+ image: postgres:13.3-alpine
24
+ command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200
25
+ environment:
26
+ POSTGRES_USER: postgres
27
+ POSTGRES_DB: rails-pg-extras-test
28
+ POSTGRES_PASSWORD: secret
29
+ ports:
30
+ - '5434:5432'
@@ -6,6 +6,7 @@ require 'ruby-pg-extras'
6
6
  module RailsPGExtras
7
7
  QUERIES = RubyPGExtras::QUERIES
8
8
  DEFAULT_ARGS = RubyPGExtras::DEFAULT_ARGS
9
+ NEW_PG_STAT_STATEMENTS = RubyPGExtras::NEW_PG_STAT_STATEMENTS
9
10
 
10
11
  QUERIES.each do |query_name|
11
12
  define_singleton_method query_name do |options = {}|
@@ -18,6 +19,16 @@ module RailsPGExtras
18
19
  end
19
20
 
20
21
  def self.run_query(query_name:, in_format:, args: {})
22
+ if %i(calls outliers).include?(query_name)
23
+ pg_stat_statements_ver = RailsPGExtras.connection.execute("select installed_version from pg_available_extensions where name='pg_stat_statements'")
24
+ .to_a[0].fetch("installed_version", nil)
25
+ if pg_stat_statements_ver != nil
26
+ if Gem::Version.new(pg_stat_statements_ver) < Gem::Version.new(NEW_PG_STAT_STATEMENTS)
27
+ query_name = "#{query_name}_legacy".to_sym
28
+ end
29
+ end
30
+ end
31
+
21
32
  sql = if (custom_args = DEFAULT_ARGS[query_name].merge(args)) != {}
22
33
  RubyPGExtras.sql_for(query_name: query_name) % custom_args
23
34
  else
@@ -36,8 +47,6 @@ module RailsPGExtras
36
47
  def self.connection
37
48
  ActiveRecord::Base.connection
38
49
  end
39
-
40
- private_class_method :connection
41
50
  end
42
51
 
43
52
  require 'rails-pg-extras/railtie' if defined?(Rails)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPGExtras
4
- VERSION = "1.6.0"
4
+ VERSION = "2.0.0"
5
5
  end
data/spec/smoke_spec.rb CHANGED
@@ -3,9 +3,12 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe RailsPGExtras do
6
- PG_STATS_DEPENDENT_QUERIES = %i(calls outliers)
6
+ before(:all) do
7
+ RailsPGExtras.connection.execute("CREATE EXTENSION IF NOT EXISTS pg_buffercache;")
8
+ RubyPGExtras.connection.exec("CREATE EXTENSION IF NOT EXISTS pg_stat_statements;")
9
+ end
7
10
 
8
- (RailsPGExtras::QUERIES - PG_STATS_DEPENDENT_QUERIES).each do |query_name|
11
+ RailsPGExtras::QUERIES.each do |query_name|
9
12
  it "#{query_name} query can be executed" do
10
13
  expect do
11
14
  RailsPGExtras.run_query(
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,19 @@ require 'bundler/setup'
5
5
  require 'active_record'
6
6
  require_relative '../lib/rails-pg-extras'
7
7
 
8
- ENV["DATABASE_URL"] ||= "postgresql://postgres:secret@localhost:5432/rails-pg-extras-test"
8
+ pg_version = ENV["PG_VERSION"]
9
+
10
+ port = if pg_version == "11"
11
+ "5432"
12
+ elsif pg_version == "12"
13
+ "5433"
14
+ elsif pg_version == "13"
15
+ "5434"
16
+ else
17
+ "5432"
18
+ end
19
+
20
+ ENV["DATABASE_URL"] ||= "postgresql://postgres:secret@localhost:#{port}/rails-pg-extras-test"
9
21
 
10
22
  RSpec.configure do |config|
11
23
  config.before :suite do
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: 1.6.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-05 00:00:00.000000000 Z
11
+ date: 2021-07-08 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: 1.6.0
19
+ version: 2.0.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: 1.6.0
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.1.4
111
+ rubygems_version: 3.1.6
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Rails PostgreSQL performance database insights