pgtk 0.27.0 → 0.28.0
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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/lib/pgtk/liquicheck_task.rb +118 -0
- data/lib/pgtk/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 757b15a689138f24c6ede8c373da30e0dce065bced0be49ecc1cde717fa44498
|
|
4
|
+
data.tar.gz: b3d1f97cb77914eda80071362d7adbaf850e2b2db810b6cc3f6fdce6d1b51f69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c2d377b1dc85c5d499665f6c57118b9c7373e8026e80eb0a21ef1a1ef5b2decffa80cdd2225f1a89cfe43e120d32f96cd64e047c841611883fc3f5dee7683284
|
|
7
|
+
data.tar.gz: 24f984d5f13d767514fd47b75920d3da94a0f6abfb4be0daf408d90846161a09c34b1607e4565a33ca3f3d5d61973496171d44f17eebab4aed50d558dd26628b
|
data/Gemfile.lock
CHANGED
|
@@ -52,7 +52,7 @@ GEM
|
|
|
52
52
|
pg (1.6.2-x64-mingw-ucrt)
|
|
53
53
|
pg (1.6.2-x86_64-linux)
|
|
54
54
|
prism (1.6.0)
|
|
55
|
-
qbash (0.4.
|
|
55
|
+
qbash (0.4.8)
|
|
56
56
|
backtrace (> 0)
|
|
57
57
|
elapsed (> 0)
|
|
58
58
|
loog (> 0)
|
|
@@ -102,7 +102,7 @@ GEM
|
|
|
102
102
|
simplecov_json_formatter (0.1.4)
|
|
103
103
|
slop (4.10.1)
|
|
104
104
|
tago (0.4.0)
|
|
105
|
-
threads (0.
|
|
105
|
+
threads (0.5.0)
|
|
106
106
|
backtrace (~> 0)
|
|
107
107
|
concurrent-ruby (~> 1.0)
|
|
108
108
|
timeout (0.4.4)
|
data/README.md
CHANGED
|
@@ -228,8 +228,8 @@ stash = Pgtk::Stash.new(
|
|
|
228
228
|
cap: 10_000, # Maximum cached query results (default: 10,000)
|
|
229
229
|
cap_interval: 60, # Seconds between cache size enforcement (default: 60)
|
|
230
230
|
refill_interval: 16, # Seconds between stale query refilling (default: 16)
|
|
231
|
-
refill_delay: 0.5, # Seconds to wait before refilling the cache
|
|
232
|
-
retire: 60, # Maximum age in seconds to keep a query in cache
|
|
231
|
+
refill_delay: 0.5, # Seconds to wait before refilling the cache
|
|
232
|
+
retire: 60, # Maximum age in seconds to keep a query in cache
|
|
233
233
|
retire_interval: 5.5, # How often to retire (default: 60)
|
|
234
234
|
threads: 4, # Worker threads for background refilling (default: 4)
|
|
235
235
|
max_queue_length: 128 # Maximum refilling tasks in queue (default: 128)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
5
|
+
|
|
6
|
+
require 'nokogiri'
|
|
7
|
+
require 'rake/tasklib'
|
|
8
|
+
require_relative '../pgtk'
|
|
9
|
+
|
|
10
|
+
# Liquicheck rake task for check Liquibase XML files.
|
|
11
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
12
|
+
# Copyright:: Copyright (c) 2019-2025 Yegor Bugayenko
|
|
13
|
+
# License:: MIT
|
|
14
|
+
class Pgtk::LiquicheckTask < Rake::TaskLib
|
|
15
|
+
# Task name
|
|
16
|
+
# @return [Symbol]
|
|
17
|
+
attr_accessor :name
|
|
18
|
+
|
|
19
|
+
# Base directory where Liquibase XML files will be stored
|
|
20
|
+
# @return [String]
|
|
21
|
+
attr_accessor :dir
|
|
22
|
+
|
|
23
|
+
# Migration XML files pattern
|
|
24
|
+
# @return [String]
|
|
25
|
+
attr_accessor :pattern
|
|
26
|
+
|
|
27
|
+
def initialize(*args, &task_block)
|
|
28
|
+
super()
|
|
29
|
+
@name = args.shift || :liquicheck
|
|
30
|
+
@dir = 'liquibase'
|
|
31
|
+
@pattern = '*/*.xml'
|
|
32
|
+
desc 'Check the quality of Liquibase XML files' unless ::Rake.application.last_description
|
|
33
|
+
task(name, *args) do |_, task_args|
|
|
34
|
+
RakeFileUtils.send(:verbose, true) do
|
|
35
|
+
yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
|
|
36
|
+
run
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def run
|
|
44
|
+
raise "Option 'dir' is mandatory" if !@dir || @dir.empty?
|
|
45
|
+
raise "Option 'pattern' is mandatory" if !@pattern || @pattern.empty?
|
|
46
|
+
errors = {}
|
|
47
|
+
Dir[File.join(File.expand_path(File.join(Dir.pwd, @dir)), @pattern)].each do |file|
|
|
48
|
+
doc = Nokogiri::XML(File.open(file))
|
|
49
|
+
doc.remove_namespaces!
|
|
50
|
+
path = doc.at_xpath('databaseChangeLog')&.attr('logicalFilePath')&.to_s
|
|
51
|
+
on(errors, file) do
|
|
52
|
+
must_have(path, 'logicalFilePath is empty')
|
|
53
|
+
must_equal(
|
|
54
|
+
path,
|
|
55
|
+
File.basename(file),
|
|
56
|
+
"logicalFilePath #{path.inspect} does not equal the xml file name #{File.basename(file).inspect}"
|
|
57
|
+
)
|
|
58
|
+
end
|
|
59
|
+
doc.xpath('databaseChangeLog/changeSet').each do |node|
|
|
60
|
+
id = node.attr('id')&.to_s
|
|
61
|
+
author = node.attr('author')&.to_s
|
|
62
|
+
context = node.attr('context')&.to_s
|
|
63
|
+
on(errors, file) do
|
|
64
|
+
must_have(id, 'ID is empty')
|
|
65
|
+
must_match(id, /[-a-z]+/, "ID #{id.inspect} has not suffix in #{context} context") if context
|
|
66
|
+
end
|
|
67
|
+
on(errors, file) do
|
|
68
|
+
must_have(author, 'author is empty')
|
|
69
|
+
must_match(
|
|
70
|
+
author,
|
|
71
|
+
/\A[-_ A-Za-z0-9]+\z/,
|
|
72
|
+
"author #{author.inspect} has illegal symbols"
|
|
73
|
+
)
|
|
74
|
+
end
|
|
75
|
+
on(errors, file) do
|
|
76
|
+
must_have(id, 'ID is empty')
|
|
77
|
+
must_have(path, 'logicalFilePath is empty')
|
|
78
|
+
must_match(
|
|
79
|
+
path.gsub(/[-_.a-z]/, ''),
|
|
80
|
+
/\A#{id.gsub(/[-a-z]/, '')}\z/,
|
|
81
|
+
"ID #{id.inspect} is not the beginning of a logicalFilePath #{path.inspect}"
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
return if errors.empty?
|
|
87
|
+
puts 'There are such errors in the Liquibase XML files.'
|
|
88
|
+
errors.each do |f, e|
|
|
89
|
+
puts "In file '#{f}':"
|
|
90
|
+
e.uniq.each do |msg|
|
|
91
|
+
puts " * #{msg}"
|
|
92
|
+
end
|
|
93
|
+
puts
|
|
94
|
+
end
|
|
95
|
+
exit(1)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def on(errors, file, &)
|
|
99
|
+
yield if block_given?
|
|
100
|
+
rescue MustError => e
|
|
101
|
+
(errors[file] ||= []) << e.message
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def must_have(prop, msg)
|
|
105
|
+
(raise MustError, msg) if prop.nil? || prop.empty?
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def must_equal(lprop, rprop, msg)
|
|
109
|
+
(raise MustError, msg) if lprop != rprop
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def must_match(prop, regex, msg)
|
|
113
|
+
(raise MustError, msg) unless prop.match?(regex)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
MustError = Class.new(StandardError)
|
|
117
|
+
private_constant :MustError
|
|
118
|
+
end
|
data/lib/pgtk/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.28.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
@@ -156,6 +156,7 @@ files:
|
|
|
156
156
|
- lib/pgtk.rb
|
|
157
157
|
- lib/pgtk/impatient.rb
|
|
158
158
|
- lib/pgtk/liquibase_task.rb
|
|
159
|
+
- lib/pgtk/liquicheck_task.rb
|
|
159
160
|
- lib/pgtk/pgsql_task.rb
|
|
160
161
|
- lib/pgtk/pool.rb
|
|
161
162
|
- lib/pgtk/retry.rb
|