pgtk 0.16.3 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f86b9a969a2e41e480e4596035128c5ac1f260eeaa4dfb0625a88316d5c34f5d
4
- data.tar.gz: d6b9dfe1dd5717f2884ba63d72b87696ddc0331983527dbb530f74a469961af6
3
+ metadata.gz: 72b30fd73fd65ec23cd7853399d575b696aef7db096b76e53d3448b881cbcf6c
4
+ data.tar.gz: 02f7a7c50eea3ce4b20862b6fcbb762e89de2259722dc034dd10c3a712345386
5
5
  SHA512:
6
- metadata.gz: 7f7433c8b02fae500929e2e62929469eae1511d958fb85d8d7a6ca56fe9010467bac3759b6f77155ec4e4d86f92b532e8f7c5bf57c83f4c6a7ce99caebc63b9d
7
- data.tar.gz: ef3a0849da8ac6678a4957868618b6c6350c86fc255285e49efd6ed3cc8dbc5503765a54abed9387d60a90e0d1c1571dd5f35e4f2daad4e8c9b5ada8e141b1d5
6
+ metadata.gz: 30707ad9cf31b00a9fca53e8c83e1197d2e6f7c3bce07856fc0f93efa5240091f31e82f99cf91940c3466e499e4cf10f46b3bf16a4476a48256ab7b120fb3f84
7
+ data.tar.gz: 0adf7b70d2921a681af1f65cd6fbc77025a96a53d678ca25f50d1c7a6c7d6173240fcd8f4475eb16383dc4d5d92868420035d64744b5660a230cca57f304b54b
@@ -12,4 +12,4 @@ jobs:
12
12
  runs-on: ubuntu-24.04
13
13
  steps:
14
14
  - uses: actions/checkout@v4
15
- - uses: yegor256/copyrights-action@0.0.8
15
+ - uses: yegor256/copyrights-action@0.0.10
@@ -20,4 +20,4 @@ jobs:
20
20
  runs-on: ubuntu-24.04
21
21
  steps:
22
22
  - uses: actions/checkout@v4
23
- - uses: articulate/actions-markdownlint@v1
23
+ - uses: DavidAnson/markdownlint-cli2-action@v20.0.0
data/Gemfile.lock CHANGED
@@ -25,8 +25,8 @@ GEM
25
25
  elapsed (0.0.1)
26
26
  loog (> 0)
27
27
  tago (> 0)
28
- joined (0.2.0)
29
- json (2.12.0)
28
+ joined (0.3.0)
29
+ json (2.12.2)
30
30
  language_server-protocol (3.17.0.5)
31
31
  lint_roller (1.1.0)
32
32
  logger (1.7.0)
@@ -57,14 +57,14 @@ GEM
57
57
  loog (> 0)
58
58
  tago (> 0)
59
59
  racc (1.8.1)
60
- rack (3.1.14)
60
+ rack (3.1.15)
61
61
  rainbow (3.1.1)
62
62
  rake (13.2.1)
63
63
  random-port (0.7.5)
64
64
  tago (> 0)
65
65
  regexp_parser (2.10.0)
66
66
  rexml (3.4.1)
67
- rubocop (1.75.6)
67
+ rubocop (1.75.7)
68
68
  json (~> 2.3)
69
69
  language_server-protocol (~> 3.17.0.2)
70
70
  lint_roller (~> 1.1.0)
data/README.md CHANGED
@@ -44,14 +44,19 @@ Then, add this to your
44
44
  ```ruby
45
45
  require 'pgtk/pgsql_task'
46
46
  Pgtk::PgsqlTask.new :pgsql do |t|
47
- t.dir = 'target/pgsql' # Temp directory with PostgreSQL files
48
- t.fresh_start = true # To delete the directory on every start
47
+ # Temp directory with PostgreSQL files:
48
+ t.dir = 'target/pgsql'
49
+ # To delete the directory on every start;
50
+ t.fresh_start = true
49
51
  t.user = 'test'
50
52
  t.password = 'test'
51
53
  t.dbname = 'test'
52
- t.yaml = 'target/pgsql-config.yml' # YAML file to be created with connection details
53
- t.contexts = '!test' # list of contexts or empty if all
54
- t.config = { # list of PostgreSQL configuration options
54
+ # YAML file to be created with connection details:
55
+ t.yaml = 'target/pgsql-config.yml'
56
+ # List of contexts or empty if all:
57
+ t.contexts = '!test'
58
+ # List of PostgreSQL configuration options:
59
+ t.config = {
55
60
  log_min_messages: 'ERROR',
56
61
  log_filename: 'target/pg.log'
57
62
  }
@@ -66,11 +71,16 @@ are used inside):
66
71
  ```ruby
67
72
  require 'pgtk/liquibase_task'
68
73
  Pgtk::LiquibaseTask.new liquibase: :pgsql do |t|
69
- t.master = 'liquibase/master.xml' # Master XML file path
70
- t.yaml = ['target/pgsql-config.yml', 'config.yml'] # YAML files with connection details
71
- t.quiet = false # TRUE by default
72
- t.postgresql_version = '42.7.0' # overwriting default version
73
- t.liquibase_version = '3.2.2' # overwriting default version
74
+ # Master XML file path:
75
+ t.master = 'liquibase/master.xml'
76
+ # YAML files connection details:
77
+ t.yaml = ['target/pgsql-config.yml', 'config.yml']
78
+ # Reduce the amount of log messages (TRUE by default):
79
+ t.quiet = false
80
+ # Overwriting default version of PostgreSQL server:
81
+ t.postgresql_version = '42.7.0'
82
+ # Overwriting default version of Liquibase:
83
+ t.liquibase_version = '3.2.2'
74
84
  end
75
85
  ```
76
86
 
@@ -3,6 +3,7 @@
3
3
  # SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
+ require 'securerandom'
6
7
  require 'tago'
7
8
  require 'timeout'
8
9
  require_relative '../pgtk'
@@ -59,9 +60,11 @@ class Pgtk::Impatient
59
60
  #
60
61
  # @param [Pgtk::Pool] pool The pool to decorate
61
62
  # @param [Integer] timeout Timeout in seconds for each SQL query
62
- def initialize(pool, timeout = 1)
63
+ # @param [Array<Regex>] off List of regex to exclude queries from checking
64
+ def initialize(pool, timeout, *off)
63
65
  @pool = pool
64
66
  @timeout = timeout
67
+ @off = off
65
68
  end
66
69
 
67
70
  # Get the version of PostgreSQL server.
@@ -78,16 +81,19 @@ class Pgtk::Impatient
78
81
  # @return [Array] Result rows
79
82
  # @raise [Timeout::Error] If the query takes too long
80
83
  def exec(sql, *args)
84
+ return @pool.exec(sql, *args) if @off.any? { |re| re.match?(sql) }
81
85
  start = Time.now
86
+ token = SecureRandom.uuid
82
87
  begin
83
- Timeout.timeout(@timeout) do
88
+ Timeout.timeout(@timeout, Timeout::Error, token) do
84
89
  @pool.exec(sql, *args)
85
90
  end
86
- rescue Timeout::Error
91
+ rescue Timeout::Error => e
92
+ raise e unless e.message == token
87
93
  raise TooSlow, [
88
94
  'SQL query',
89
- ("with #{args.count} arguments" unless args.empty?),
90
- 'stopped after',
95
+ ("with #{args.count} argument#{'s' if args.count > 1}" unless args.empty?),
96
+ 'was terminated after',
91
97
  start.ago,
92
98
  'of waiting'
93
99
  ].compact.join(' ')
data/lib/pgtk/version.rb CHANGED
@@ -11,5 +11,5 @@ require_relative '../pgtk'
11
11
  # License:: MIT
12
12
  module Pgtk
13
13
  # Current version of the library.
14
- VERSION = '0.16.3'
14
+ VERSION = '0.17.1'
15
15
  end
data/resources/pom.xml CHANGED
@@ -11,7 +11,7 @@
11
11
  <packaging>pom</packaging>
12
12
  <properties>
13
13
  <postgresql.version>42.7.5</postgresql.version>
14
- <liquibase.version>4.31.1</liquibase.version>
14
+ <liquibase.version>4.32.0</liquibase.version>
15
15
  </properties>
16
16
  <dependencies>
17
17
  <dependency>
@@ -20,7 +20,7 @@ require_relative '../lib/pgtk/impatient'
20
20
  class TestImpatient < Pgtk::Test
21
21
  def test_takes_version
22
22
  fake_pool do |pool|
23
- v = Pgtk::Impatient.new(pool).version
23
+ v = Pgtk::Impatient.new(pool, 1).version
24
24
  refute_nil(v)
25
25
  end
26
26
  end
@@ -28,16 +28,36 @@ class TestImpatient < Pgtk::Test
28
28
  def test_interrupts
29
29
  fake_pool do |pool|
30
30
  assert_raises(Pgtk::Impatient::TooSlow) do
31
- Pgtk::Impatient.new(pool, 0.1).exec(
32
- 'SELECT COUNT(*) FROM generate_series(1, 10000000) AS a'
31
+ Pgtk::Impatient.new(pool, 0.01).exec(
32
+ 'SELECT COUNT(*) FROM generate_series(1, 1000000) AS a'
33
33
  )
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
+ def test_skips_by_regex
39
+ fake_pool do |pool|
40
+ Pgtk::Impatient.new(pool, 0.01, /^SELECT.*$/).exec(
41
+ 'SELECT COUNT(*) FROM generate_series(1, 1000000) AS a'
42
+ )
43
+ end
44
+ end
45
+
46
+ def test_doesnt_shadow_larger_timeout
47
+ fake_pool do |pool|
48
+ assert_raises(Timeout::Error) do
49
+ Timeout.timeout(0.1) do
50
+ Pgtk::Impatient.new(pool, 999).exec(
51
+ 'SELECT COUNT(*) FROM generate_series(1, 100000000) AS a'
52
+ )
53
+ end
54
+ end
55
+ end
56
+ end
57
+
38
58
  def test_doesnt_interrupt
39
59
  fake_pool do |pool|
40
- id = Pgtk::Impatient.new(pool).exec(
60
+ id = Pgtk::Impatient.new(pool, 1).exec(
41
61
  'INSERT INTO book (title) VALUES ($1) RETURNING id',
42
62
  ['1984']
43
63
  ).first['id'].to_i
@@ -47,7 +67,7 @@ class TestImpatient < Pgtk::Test
47
67
 
48
68
  def test_doesnt_interrupt_in_transaction
49
69
  fake_pool do |pool|
50
- Pgtk::Impatient.new(pool).transaction do |t|
70
+ Pgtk::Impatient.new(pool, 1).transaction do |t|
51
71
  id = t.exec(
52
72
  'INSERT INTO book (title) VALUES ($1) RETURNING id',
53
73
  ['1984']
data/test/test_pool.rb CHANGED
@@ -38,6 +38,35 @@ class TestPool < Pgtk::Test
38
38
  end
39
39
  end
40
40
 
41
+ def test_logs_pgsql_errors_to_logger
42
+ buf = Loog::Buffer.new
43
+ fake_pool(log: buf) do |pool|
44
+ pool.exec(
45
+ "
46
+ CREATE FUNCTION intentional_failure() RETURNS trigger AS
47
+ 'BEGIN
48
+ IF NEW.title = ''War and War'' THEN
49
+ RAISE EXCEPTION ''The title of the book is bad'';
50
+ END IF;
51
+ RETURN NEW;
52
+ END' LANGUAGE PLPGSQL
53
+ "
54
+ )
55
+ pool.exec(
56
+ "
57
+ CREATE TRIGGER check_book_title
58
+ BEFORE INSERT ON book
59
+ FOR EACH ROW EXECUTE PROCEDURE intentional_failure();
60
+ "
61
+ )
62
+ assert_raises(PG::RaiseException) do
63
+ pool.exec('INSERT INTO book (title) VALUES ($1)', ['War and War'])
64
+ end
65
+ assert_includes(buf.to_s, 'The title of the book is bad')
66
+ assert_includes(buf.to_s, 'function intentional_failure() line 3')
67
+ end
68
+ end
69
+
41
70
  def test_queries_with_block
42
71
  fake_pool do |pool|
43
72
  pool.exec('INSERT INTO book (title) VALUES ($1)', ['1984'])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.3
4
+ version: 0.17.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko