pg_objects 1.0.3 → 1.2.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/.github/dependabot.yml +11 -0
- data/.github/workflows/ci.yml +1 -1
- data/.rubocop.yml +4 -1
- data/Gemfile +2 -1
- data/Gemfile.lock +158 -72
- data/lib/generators/pg_objects/install/install_generator.rb +7 -9
- data/lib/pg_objects/db_object.rb +26 -19
- data/lib/pg_objects/logger.rb +16 -13
- data/lib/pg_objects/manager.rb +50 -52
- data/lib/pg_objects/parser.rb +92 -43
- data/lib/pg_objects/railtie.rb +7 -9
- data/lib/pg_objects/version.rb +1 -1
- data/pg_objects.gemspec +4 -4
- metadata +13 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7020b30da04ae39e82f938692675d38dd4b65c8d0e354be2fc5198c726e41608
|
|
4
|
+
data.tar.gz: d436471478f54272dc91ee41f0a0d72571f54fb1eb4d886c7b3d881b5aea6bd5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70c31c6788728cf943e6973ee4aaa9fe34238613bf1d07f6fa7b7de020fcb96de0deccdb79d0c79c1cf20c399039171a16c8a2f7125d44934da5106af10f66e3
|
|
7
|
+
data.tar.gz: b4f122ce4aaead24702761ac44d8330f63e3daaac85448aef6dc8c14295ec3f6658731934db48c39eebbcef4e27d1bffde0edb137876820df38558fe5e10c3ce
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: "bundler"
|
|
9
|
+
directory: "/" # Location of package manifests
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "weekly"
|
data/.github/workflows/ci.yml
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -8,7 +8,7 @@ inherit_from: .rubocop_todo.yml
|
|
|
8
8
|
|
|
9
9
|
AllCops:
|
|
10
10
|
# EnabledByDefault: true
|
|
11
|
-
TargetRubyVersion:
|
|
11
|
+
TargetRubyVersion: 3.1
|
|
12
12
|
# Cop names are not d§splayed in offense messages by default. Change behavior
|
|
13
13
|
# by overriding DisplayCopNames, or by giving the -D/--display-cop-names
|
|
14
14
|
# option.
|
|
@@ -210,6 +210,9 @@ Style/BisectedAttrAccessor:
|
|
|
210
210
|
Style/CaseLikeIf:
|
|
211
211
|
Enabled: true
|
|
212
212
|
|
|
213
|
+
Style/ClassAndModuleChildren:
|
|
214
|
+
EnforcedStyle: compact
|
|
215
|
+
|
|
213
216
|
Style/ExponentialNotation:
|
|
214
217
|
Enabled: true
|
|
215
218
|
|
data/Gemfile
CHANGED
|
@@ -5,9 +5,10 @@ gemspec
|
|
|
5
5
|
group :development, :test do
|
|
6
6
|
gem 'bundler', require: false
|
|
7
7
|
gem 'bundler-audit', require: false
|
|
8
|
-
gem 'byebug'
|
|
8
|
+
gem 'pry-byebug'
|
|
9
9
|
gem 'rake', require: false
|
|
10
10
|
gem 'rspec', require: false
|
|
11
|
+
gem 'rspec-parameterized', require: false
|
|
11
12
|
gem 'rubocop', require: false
|
|
12
13
|
gem 'rubocop-rails', require: false
|
|
13
14
|
gem 'rubocop-rake', require: false
|
data/Gemfile.lock
CHANGED
|
@@ -1,150 +1,236 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
pg_objects (1.0
|
|
5
|
-
activerecord (>= 6.
|
|
6
|
-
pg_query (~>
|
|
7
|
-
railties (>= 4, <
|
|
4
|
+
pg_objects (1.2.0)
|
|
5
|
+
activerecord (>= 6.1.7.0, < 8)
|
|
6
|
+
pg_query (~> 5)
|
|
7
|
+
railties (>= 4, < 8)
|
|
8
8
|
rake-hooks (~> 1)
|
|
9
9
|
|
|
10
10
|
GEM
|
|
11
11
|
remote: https://rubygems.org/
|
|
12
12
|
specs:
|
|
13
|
-
actionpack (
|
|
14
|
-
actionview (=
|
|
15
|
-
activesupport (=
|
|
16
|
-
|
|
13
|
+
actionpack (7.1.3.2)
|
|
14
|
+
actionview (= 7.1.3.2)
|
|
15
|
+
activesupport (= 7.1.3.2)
|
|
16
|
+
nokogiri (>= 1.8.5)
|
|
17
|
+
racc
|
|
18
|
+
rack (>= 2.2.4)
|
|
19
|
+
rack-session (>= 1.0.1)
|
|
17
20
|
rack-test (>= 0.6.3)
|
|
18
|
-
rails-dom-testing (~> 2.
|
|
19
|
-
rails-html-sanitizer (~> 1.
|
|
20
|
-
actionview (
|
|
21
|
-
activesupport (=
|
|
21
|
+
rails-dom-testing (~> 2.2)
|
|
22
|
+
rails-html-sanitizer (~> 1.6)
|
|
23
|
+
actionview (7.1.3.2)
|
|
24
|
+
activesupport (= 7.1.3.2)
|
|
22
25
|
builder (~> 3.1)
|
|
23
|
-
erubi (~> 1.
|
|
24
|
-
rails-dom-testing (~> 2.
|
|
25
|
-
rails-html-sanitizer (~> 1.
|
|
26
|
-
activemodel (
|
|
27
|
-
activesupport (=
|
|
28
|
-
activerecord (
|
|
29
|
-
activemodel (=
|
|
30
|
-
activesupport (=
|
|
31
|
-
|
|
26
|
+
erubi (~> 1.11)
|
|
27
|
+
rails-dom-testing (~> 2.2)
|
|
28
|
+
rails-html-sanitizer (~> 1.6)
|
|
29
|
+
activemodel (7.1.3.2)
|
|
30
|
+
activesupport (= 7.1.3.2)
|
|
31
|
+
activerecord (7.1.3.2)
|
|
32
|
+
activemodel (= 7.1.3.2)
|
|
33
|
+
activesupport (= 7.1.3.2)
|
|
34
|
+
timeout (>= 0.4.0)
|
|
35
|
+
activesupport (7.1.3.2)
|
|
36
|
+
base64
|
|
37
|
+
bigdecimal
|
|
32
38
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
39
|
+
connection_pool (>= 2.2.5)
|
|
40
|
+
drb
|
|
33
41
|
i18n (>= 1.6, < 2)
|
|
34
42
|
minitest (>= 5.1)
|
|
43
|
+
mutex_m
|
|
35
44
|
tzinfo (~> 2.0)
|
|
36
|
-
zeitwerk (~> 2.3)
|
|
37
45
|
ast (2.4.2)
|
|
46
|
+
base64 (0.2.0)
|
|
47
|
+
bigdecimal (3.1.6)
|
|
48
|
+
binding_of_caller (1.0.0)
|
|
49
|
+
debug_inspector (>= 0.0.1)
|
|
38
50
|
builder (3.2.4)
|
|
39
51
|
bundler-audit (0.9.1)
|
|
40
52
|
bundler (>= 1.2.0, < 3)
|
|
41
53
|
thor (~> 1.0)
|
|
42
54
|
byebug (11.1.3)
|
|
43
|
-
|
|
55
|
+
coderay (1.1.3)
|
|
56
|
+
concurrent-ruby (1.2.3)
|
|
57
|
+
connection_pool (2.4.1)
|
|
44
58
|
crass (1.0.6)
|
|
45
|
-
|
|
59
|
+
debug_inspector (1.2.0)
|
|
60
|
+
diff-lcs (1.5.1)
|
|
61
|
+
drb (2.2.0)
|
|
62
|
+
ruby2_keywords
|
|
46
63
|
erubi (1.12.0)
|
|
64
|
+
google-protobuf (3.25.3)
|
|
65
|
+
google-protobuf (3.25.3-aarch64-linux)
|
|
66
|
+
google-protobuf (3.25.3-arm64-darwin)
|
|
67
|
+
google-protobuf (3.25.3-x86-linux)
|
|
68
|
+
google-protobuf (3.25.3-x86_64-darwin)
|
|
69
|
+
google-protobuf (3.25.3-x86_64-linux)
|
|
47
70
|
i18n (1.14.1)
|
|
48
71
|
concurrent-ruby (~> 1.0)
|
|
49
|
-
|
|
72
|
+
io-console (0.7.2)
|
|
73
|
+
irb (1.11.2)
|
|
74
|
+
rdoc
|
|
75
|
+
reline (>= 0.4.2)
|
|
76
|
+
json (2.7.1)
|
|
50
77
|
language_server-protocol (3.17.0.3)
|
|
51
|
-
loofah (2.
|
|
78
|
+
loofah (2.22.0)
|
|
52
79
|
crass (~> 1.0.2)
|
|
53
80
|
nokogiri (>= 1.12.0)
|
|
54
81
|
method_source (1.0.0)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
nokogiri (1.
|
|
58
|
-
|
|
82
|
+
minitest (5.22.2)
|
|
83
|
+
mutex_m (0.2.0)
|
|
84
|
+
nokogiri (1.16.2-aarch64-linux)
|
|
85
|
+
racc (~> 1.4)
|
|
86
|
+
nokogiri (1.16.2-arm-linux)
|
|
87
|
+
racc (~> 1.4)
|
|
88
|
+
nokogiri (1.16.2-arm64-darwin)
|
|
89
|
+
racc (~> 1.4)
|
|
90
|
+
nokogiri (1.16.2-x86-linux)
|
|
91
|
+
racc (~> 1.4)
|
|
92
|
+
nokogiri (1.16.2-x86_64-darwin)
|
|
59
93
|
racc (~> 1.4)
|
|
60
|
-
|
|
61
|
-
|
|
94
|
+
nokogiri (1.16.2-x86_64-linux)
|
|
95
|
+
racc (~> 1.4)
|
|
96
|
+
parallel (1.24.0)
|
|
97
|
+
parser (3.3.0.5)
|
|
62
98
|
ast (~> 2.4.1)
|
|
63
99
|
racc
|
|
64
|
-
pg_query (1.
|
|
65
|
-
|
|
66
|
-
|
|
100
|
+
pg_query (5.1.0)
|
|
101
|
+
google-protobuf (>= 3.22.3)
|
|
102
|
+
proc_to_ast (0.1.0)
|
|
103
|
+
coderay
|
|
104
|
+
parser
|
|
105
|
+
unparser
|
|
106
|
+
pry (0.14.2)
|
|
107
|
+
coderay (~> 1.1)
|
|
108
|
+
method_source (~> 1.0)
|
|
109
|
+
pry-byebug (3.10.1)
|
|
110
|
+
byebug (~> 11.0)
|
|
111
|
+
pry (>= 0.13, < 0.15)
|
|
112
|
+
psych (5.1.2)
|
|
113
|
+
stringio
|
|
114
|
+
racc (1.7.3)
|
|
115
|
+
rack (3.0.9.1)
|
|
116
|
+
rack-session (2.0.0)
|
|
117
|
+
rack (>= 3.0.0)
|
|
67
118
|
rack-test (2.1.0)
|
|
68
119
|
rack (>= 1.3)
|
|
69
|
-
|
|
70
|
-
|
|
120
|
+
rackup (2.1.0)
|
|
121
|
+
rack (>= 3)
|
|
122
|
+
webrick (~> 1.8)
|
|
123
|
+
rails-dom-testing (2.2.0)
|
|
124
|
+
activesupport (>= 5.0.0)
|
|
125
|
+
minitest
|
|
71
126
|
nokogiri (>= 1.6)
|
|
72
127
|
rails-html-sanitizer (1.6.0)
|
|
73
128
|
loofah (~> 2.21)
|
|
74
129
|
nokogiri (~> 1.14)
|
|
75
|
-
railties (
|
|
76
|
-
actionpack (=
|
|
77
|
-
activesupport (=
|
|
78
|
-
|
|
130
|
+
railties (7.1.3.2)
|
|
131
|
+
actionpack (= 7.1.3.2)
|
|
132
|
+
activesupport (= 7.1.3.2)
|
|
133
|
+
irb
|
|
134
|
+
rackup (>= 1.0.0)
|
|
79
135
|
rake (>= 12.2)
|
|
80
|
-
thor (~> 1.0)
|
|
136
|
+
thor (~> 1.0, >= 1.2.2)
|
|
137
|
+
zeitwerk (~> 2.6)
|
|
81
138
|
rainbow (3.1.1)
|
|
82
|
-
rake (13.0
|
|
139
|
+
rake (13.1.0)
|
|
83
140
|
rake-hooks (1.2.3)
|
|
84
141
|
rake
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
rspec
|
|
92
|
-
rspec-
|
|
93
|
-
|
|
142
|
+
rdoc (6.6.2)
|
|
143
|
+
psych (>= 4.0.0)
|
|
144
|
+
regexp_parser (2.9.0)
|
|
145
|
+
reline (0.4.3)
|
|
146
|
+
io-console (~> 0.5)
|
|
147
|
+
rexml (3.2.6)
|
|
148
|
+
rspec (3.13.0)
|
|
149
|
+
rspec-core (~> 3.13.0)
|
|
150
|
+
rspec-expectations (~> 3.13.0)
|
|
151
|
+
rspec-mocks (~> 3.13.0)
|
|
152
|
+
rspec-core (3.13.0)
|
|
153
|
+
rspec-support (~> 3.13.0)
|
|
154
|
+
rspec-expectations (3.13.0)
|
|
94
155
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
95
|
-
rspec-support (~> 3.
|
|
96
|
-
rspec-mocks (3.
|
|
156
|
+
rspec-support (~> 3.13.0)
|
|
157
|
+
rspec-mocks (3.13.0)
|
|
97
158
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
98
|
-
rspec-support (~> 3.
|
|
99
|
-
rspec-
|
|
100
|
-
|
|
159
|
+
rspec-support (~> 3.13.0)
|
|
160
|
+
rspec-parameterized (1.0.0)
|
|
161
|
+
rspec-parameterized-core (< 2)
|
|
162
|
+
rspec-parameterized-table_syntax (< 2)
|
|
163
|
+
rspec-parameterized-core (1.0.0)
|
|
164
|
+
parser
|
|
165
|
+
proc_to_ast
|
|
166
|
+
rspec (>= 2.13, < 4)
|
|
167
|
+
unparser
|
|
168
|
+
rspec-parameterized-table_syntax (1.0.1)
|
|
169
|
+
binding_of_caller
|
|
170
|
+
rspec-parameterized-core (< 2)
|
|
171
|
+
rspec-support (3.13.1)
|
|
172
|
+
rubocop (1.60.2)
|
|
101
173
|
json (~> 2.3)
|
|
102
174
|
language_server-protocol (>= 3.17.0)
|
|
103
175
|
parallel (~> 1.10)
|
|
104
|
-
parser (>= 3.
|
|
176
|
+
parser (>= 3.3.0.2)
|
|
105
177
|
rainbow (>= 2.2.2, < 4.0)
|
|
106
178
|
regexp_parser (>= 1.8, < 3.0)
|
|
107
179
|
rexml (>= 3.2.5, < 4.0)
|
|
108
|
-
rubocop-ast (>= 1.
|
|
180
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
109
181
|
ruby-progressbar (~> 1.7)
|
|
110
182
|
unicode-display_width (>= 2.4.0, < 3.0)
|
|
111
|
-
rubocop-ast (1.
|
|
183
|
+
rubocop-ast (1.30.0)
|
|
112
184
|
parser (>= 3.2.1.0)
|
|
113
|
-
rubocop-capybara (2.
|
|
185
|
+
rubocop-capybara (2.20.0)
|
|
186
|
+
rubocop (~> 1.41)
|
|
187
|
+
rubocop-factory_bot (2.25.1)
|
|
114
188
|
rubocop (~> 1.41)
|
|
115
|
-
rubocop-
|
|
116
|
-
rubocop (~> 1.33)
|
|
117
|
-
rubocop-rails (2.20.2)
|
|
189
|
+
rubocop-rails (2.23.1)
|
|
118
190
|
activesupport (>= 4.2.0)
|
|
119
191
|
rack (>= 1.1)
|
|
120
192
|
rubocop (>= 1.33.0, < 2.0)
|
|
193
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
121
194
|
rubocop-rake (0.6.0)
|
|
122
195
|
rubocop (~> 1.0)
|
|
123
|
-
rubocop-rspec (2.
|
|
124
|
-
rubocop (~> 1.
|
|
196
|
+
rubocop-rspec (2.26.1)
|
|
197
|
+
rubocop (~> 1.40)
|
|
125
198
|
rubocop-capybara (~> 2.17)
|
|
126
199
|
rubocop-factory_bot (~> 2.22)
|
|
127
200
|
ruby-progressbar (1.13.0)
|
|
128
|
-
|
|
201
|
+
ruby2_keywords (0.0.5)
|
|
202
|
+
stringio (3.1.0)
|
|
203
|
+
thor (1.3.1)
|
|
204
|
+
timeout (0.4.1)
|
|
129
205
|
tzinfo (2.0.6)
|
|
130
206
|
concurrent-ruby (~> 1.0)
|
|
131
|
-
unicode-display_width (2.
|
|
132
|
-
|
|
207
|
+
unicode-display_width (2.5.0)
|
|
208
|
+
unparser (0.6.13)
|
|
209
|
+
diff-lcs (~> 1.3)
|
|
210
|
+
parser (>= 3.3.0)
|
|
211
|
+
webrick (1.8.1)
|
|
212
|
+
zeitwerk (2.6.13)
|
|
133
213
|
|
|
134
214
|
PLATFORMS
|
|
135
|
-
|
|
215
|
+
aarch64-linux
|
|
216
|
+
arm-linux
|
|
217
|
+
arm64-darwin
|
|
218
|
+
x86-linux
|
|
219
|
+
x86_64-darwin
|
|
220
|
+
x86_64-linux
|
|
136
221
|
|
|
137
222
|
DEPENDENCIES
|
|
138
223
|
bundler
|
|
139
224
|
bundler-audit
|
|
140
|
-
byebug
|
|
141
225
|
pg_objects!
|
|
226
|
+
pry-byebug
|
|
142
227
|
rake
|
|
143
228
|
rspec
|
|
229
|
+
rspec-parameterized
|
|
144
230
|
rubocop
|
|
145
231
|
rubocop-rails
|
|
146
232
|
rubocop-rake
|
|
147
233
|
rubocop-rspec
|
|
148
234
|
|
|
149
235
|
BUNDLED WITH
|
|
150
|
-
2.
|
|
236
|
+
2.5.5
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
empty_directory 'db/objects/after'
|
|
9
|
-
end
|
|
1
|
+
##
|
|
2
|
+
# Creates default directories structure
|
|
3
|
+
class PgObjects::InstallGenerator < Rails::Generators::Base
|
|
4
|
+
def create_directories
|
|
5
|
+
empty_directory 'db/objects'
|
|
6
|
+
empty_directory 'db/objects/before'
|
|
7
|
+
empty_directory 'db/objects/after'
|
|
10
8
|
end
|
|
11
9
|
end
|
data/lib/pg_objects/db_object.rb
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
attr_accessor :status
|
|
1
|
+
##
|
|
2
|
+
# Represents DB object as it is described in file
|
|
3
|
+
#
|
|
4
|
+
# [name] name of file without extension
|
|
5
|
+
# [full_name] full pathname of file
|
|
6
|
+
# [object_name] name of function, trigger etc. if it was successfully parsed, otherwise - nil
|
|
7
|
+
class PgObjects::DbObject
|
|
8
|
+
attr_reader :sql_query, :name, :full_name, :object_name, :dependencies
|
|
9
|
+
attr_accessor :status
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@sql_query = File.read file_path
|
|
11
|
+
def initialize(file_path)
|
|
12
|
+
@full_name = file_path
|
|
13
|
+
@name = File.basename(file_path, '.*')
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
@status = :new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create
|
|
19
|
+
@sql_query = File.read(full_name)
|
|
20
|
+
|
|
21
|
+
parser = PgObjects::Parser.new(sql_query)
|
|
22
|
+
|
|
23
|
+
directives = parser.fetch_directives
|
|
24
|
+
@dependencies = directives[:depends_on]
|
|
25
|
+
@object_name = parser.fetch_object_name
|
|
26
|
+
|
|
27
|
+
@status = :pending
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
end
|
|
29
|
+
self
|
|
23
30
|
end
|
|
24
31
|
end
|
data/lib/pg_objects/logger.rb
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Logger
|
|
7
|
-
attr_reader :silent
|
|
1
|
+
##
|
|
2
|
+
# Console output
|
|
3
|
+
#
|
|
4
|
+
class PgObjects::Logger
|
|
5
|
+
attr_reader :silent
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
def initialize
|
|
8
|
+
@silent = false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def write(str)
|
|
12
|
+
puts "== #{str} ".ljust(80, '=') unless silent
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def mute(value)
|
|
16
|
+
@silent = value
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
puts "== #{str} ".ljust(80, '=') unless silent
|
|
15
|
-
end
|
|
18
|
+
self
|
|
16
19
|
end
|
|
17
20
|
end
|
data/lib/pg_objects/manager.rb
CHANGED
|
@@ -1,69 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
attr_reader :objects, :config, :log
|
|
1
|
+
##
|
|
2
|
+
# Manages process to create objects
|
|
3
|
+
#
|
|
4
|
+
# Usage:
|
|
5
|
+
#
|
|
6
|
+
# Manager.new(config, logger).load_files(:before).create_objects
|
|
7
|
+
#
|
|
8
|
+
# or
|
|
9
|
+
#
|
|
10
|
+
# Manager.new(config, logger).load_files(:after).create_objects
|
|
11
|
+
class PgObjects::Manager
|
|
12
|
+
attr_reader :objects, :config
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
def initialize(config, logger)
|
|
15
|
+
raise PgObjects::UnsupportedAdapterError if ActiveRecord::Base.connection.adapter_name != 'PostgreSQL'
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
##
|
|
24
|
-
# event: +:before+ or +:after+
|
|
25
|
-
#
|
|
26
|
-
# used to reference configuration settings +before_path+ and +after_path+
|
|
27
|
-
def load_files(event)
|
|
28
|
-
dir = config.send "#{event}_path"
|
|
29
|
-
Dir[File.join(dir, '**', "*.{#{config.extensions.join(',')}}")].each do |path|
|
|
30
|
-
@objects << PgObjects::DbObject.new(path)
|
|
31
|
-
end
|
|
17
|
+
@objects = []
|
|
18
|
+
@config = config
|
|
19
|
+
@log = logger.mute(config.silent) # Logger.new(silent: config.silent)
|
|
20
|
+
end
|
|
32
21
|
|
|
33
|
-
|
|
22
|
+
##
|
|
23
|
+
# event: +:before+ or +:after+
|
|
24
|
+
#
|
|
25
|
+
# used to reference configuration settings +before_path+ and +after_path+
|
|
26
|
+
def load_files(event)
|
|
27
|
+
dir = config.send "#{event}_path"
|
|
28
|
+
Dir[File.join(dir, '**', "*.{#{config.extensions.join(',')}}")].each do |path|
|
|
29
|
+
@objects << PgObjects::DbObject.new(path).create
|
|
34
30
|
end
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
end
|
|
32
|
+
self
|
|
33
|
+
end
|
|
39
34
|
|
|
40
|
-
|
|
35
|
+
def create_objects
|
|
36
|
+
objects.each { create_object(_1) }
|
|
37
|
+
end
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
return if obj.status == :done
|
|
44
|
-
raise CyclicDependencyError, obj.name if obj.status == :processing
|
|
39
|
+
private
|
|
45
40
|
|
|
46
|
-
|
|
41
|
+
def create_object(obj)
|
|
42
|
+
return if obj.status == :done
|
|
43
|
+
raise PgObjects::CyclicDependencyError, obj.name if obj.status == :processing
|
|
47
44
|
|
|
48
|
-
|
|
45
|
+
obj.status = :processing
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
ActiveRecord::Base.connection.execute obj.sql_query
|
|
47
|
+
create_dependencies(obj.dependencies)
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
@log.write("creating #{obj.name}")
|
|
50
|
+
ActiveRecord::Base.connection.execute obj.sql_query
|
|
55
51
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
obj.status = :done
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def create_dependencies(dependencies)
|
|
56
|
+
dependencies.each { |dep_name| create_object(find_object(dep_name)) }
|
|
57
|
+
end
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
def find_object(dep_name)
|
|
60
|
+
result = @objects.select { |obj| [obj.name, obj.full_name, obj.object_name].compact.include? dep_name }
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
raise PgObjects::AmbiguousDependencyError, dep_name if result.size > 1
|
|
63
|
+
raise PgObjects::DependencyNotExistError, dep_name if result.empty?
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
end
|
|
65
|
+
result[0]
|
|
68
66
|
end
|
|
69
67
|
end
|
data/lib/pg_objects/parser.rb
CHANGED
|
@@ -1,47 +1,96 @@
|
|
|
1
1
|
require 'pg_query'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
3
|
+
##
|
|
4
|
+
# Reads directives from SQL-comments
|
|
5
|
+
#
|
|
6
|
+
# --!depends_on [name_of_dependency]
|
|
7
|
+
#
|
|
8
|
+
# name_of_dependency: short or full name of object as well as object_name
|
|
9
|
+
#
|
|
10
|
+
class PgObjects::Parser
|
|
11
|
+
PG_ENTITIES = %i[operator_class trigger define_statement conversion event_trigger type function table].freeze
|
|
12
|
+
|
|
13
|
+
def initialize(source)
|
|
14
|
+
@source = source
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def fetch_directives
|
|
18
|
+
{
|
|
19
|
+
depends_on: fetch_dependencies
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def fetch_object_name
|
|
24
|
+
parse_query
|
|
25
|
+
object_name
|
|
26
|
+
rescue PgQuery::ParseError, NoMethodError
|
|
27
|
+
nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
attr_reader :stmt, :parsed
|
|
33
|
+
|
|
34
|
+
def parse_query
|
|
35
|
+
@parsed = PgQuery.parse(@source)
|
|
36
|
+
|
|
37
|
+
@stmt = parsed.tree.stmts[0].stmt
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def object_name
|
|
41
|
+
PG_ENTITIES.filter_map { |entity| send(:"check_#{entity}") }.first
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def fetch_dependencies
|
|
45
|
+
@source.split("\n").grep(/^(--|#)!/).map { |ln| ln.split[1] if ln =~ /!depends_on/ }.compact
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# also views
|
|
49
|
+
def table? = parsed.tables.size.positive?
|
|
50
|
+
|
|
51
|
+
def check_table
|
|
52
|
+
parsed.tables[0] if table?
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def function? = parsed.functions.size.positive?
|
|
56
|
+
|
|
57
|
+
def check_function
|
|
58
|
+
parsed.functions[0] if function?
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def operator_class? = stmt.respond_to?(:create_op_class_stmt) && stmt.create_op_class_stmt.present?
|
|
62
|
+
|
|
63
|
+
def check_operator_class
|
|
64
|
+
stmt.create_op_class_stmt.opclassname[0].string.sval if operator_class?
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def trigger? = stmt.respond_to?(:create_trig_stmt) && stmt.create_trig_stmt.present?
|
|
68
|
+
|
|
69
|
+
def check_trigger
|
|
70
|
+
stmt.create_trig_stmt.trigname if trigger?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def define_statement? = stmt.respond_to?(:define_stmt) && stmt.define_stmt.present?
|
|
74
|
+
|
|
75
|
+
def check_define_statement
|
|
76
|
+
stmt.define_stmt.defnames[0].string.sval if define_statement?
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def conversion? = stmt.respond_to?(:create_conversion_stmt) && stmt.create_conversion_stmt.present?
|
|
80
|
+
|
|
81
|
+
def check_conversion
|
|
82
|
+
stmt.create_conversion_stmt.conversion_name[0].string.sval if conversion?
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def event_trigger? = stmt.respond_to?(:create_event_trig_stmt) && stmt.create_event_trig_stmt.present?
|
|
86
|
+
|
|
87
|
+
def check_event_trigger
|
|
88
|
+
stmt.create_event_trig_stmt.trigname if event_trigger?
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def type? = stmt.respond_to?(:composite_type_stmt) && stmt.composite_type_stmt.present?
|
|
92
|
+
|
|
93
|
+
def check_type
|
|
94
|
+
stmt.composite_type_stmt.typevar.relname if type?
|
|
46
95
|
end
|
|
47
96
|
end
|
data/lib/pg_objects/railtie.rb
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
# end
|
|
1
|
+
##
|
|
2
|
+
# Brings rake tasks to rails app
|
|
3
|
+
class PgObjects::Railtie < Rails::Railtie
|
|
4
|
+
# initializer 'pg_objects.initialization' do |app|
|
|
5
|
+
# end
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
end
|
|
7
|
+
rake_tasks do
|
|
8
|
+
load 'tasks/pg_objects_tasks.rake'
|
|
11
9
|
end
|
|
12
10
|
end
|
data/lib/pg_objects/version.rb
CHANGED
data/pg_objects.gemspec
CHANGED
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.summary = %q(Simple manager for PostgreSQL objects like triggers and functions)
|
|
12
12
|
spec.homepage = 'https://github.com/marinazzio/pg_objects'
|
|
13
13
|
|
|
14
|
-
spec.required_ruby_version = '>=
|
|
14
|
+
spec.required_ruby_version = '>= 3.1.0'
|
|
15
15
|
|
|
16
16
|
spec.metadata = {
|
|
17
17
|
'bug_tracker_uri' => 'https://github.com/marinazzio/pg_objects/issues',
|
|
@@ -43,8 +43,8 @@ Gem::Specification.new do |spec|
|
|
|
43
43
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
44
44
|
spec.require_paths = ['lib']
|
|
45
45
|
|
|
46
|
-
spec.add_dependency 'activerecord', '>= 6.
|
|
47
|
-
spec.add_dependency 'pg_query', '~>
|
|
48
|
-
spec.add_dependency 'railties', '>= 4', '<
|
|
46
|
+
spec.add_dependency 'activerecord', '>= 6.1.7.0', '< 8'
|
|
47
|
+
spec.add_dependency 'pg_query', '~> 5'
|
|
48
|
+
spec.add_dependency 'railties', '>= 4', '< 8'
|
|
49
49
|
spec.add_dependency 'rake-hooks', '~> 1'
|
|
50
50
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pg_objects
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Denis Kiselyov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-02-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -16,34 +16,34 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 6.
|
|
19
|
+
version: 6.1.7.0
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '
|
|
22
|
+
version: '8'
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 6.
|
|
29
|
+
version: 6.1.7.0
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '8'
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
34
|
name: pg_query
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
39
|
+
version: '5'
|
|
40
40
|
type: :runtime
|
|
41
41
|
prerelease: false
|
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
44
|
- - "~>"
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '
|
|
46
|
+
version: '5'
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: railties
|
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -53,7 +53,7 @@ dependencies:
|
|
|
53
53
|
version: '4'
|
|
54
54
|
- - "<"
|
|
55
55
|
- !ruby/object:Gem::Version
|
|
56
|
-
version: '
|
|
56
|
+
version: '8'
|
|
57
57
|
type: :runtime
|
|
58
58
|
prerelease: false
|
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -63,7 +63,7 @@ dependencies:
|
|
|
63
63
|
version: '4'
|
|
64
64
|
- - "<"
|
|
65
65
|
- !ruby/object:Gem::Version
|
|
66
|
-
version: '
|
|
66
|
+
version: '8'
|
|
67
67
|
- !ruby/object:Gem::Dependency
|
|
68
68
|
name: rake-hooks
|
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -85,6 +85,7 @@ executables: []
|
|
|
85
85
|
extensions: []
|
|
86
86
|
extra_rdoc_files: []
|
|
87
87
|
files:
|
|
88
|
+
- ".github/dependabot.yml"
|
|
88
89
|
- ".github/workflows/bundle_audit.yml"
|
|
89
90
|
- ".github/workflows/ci.yml"
|
|
90
91
|
- ".gitignore"
|
|
@@ -132,14 +133,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
132
133
|
requirements:
|
|
133
134
|
- - ">="
|
|
134
135
|
- !ruby/object:Gem::Version
|
|
135
|
-
version:
|
|
136
|
+
version: 3.1.0
|
|
136
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
138
|
requirements:
|
|
138
139
|
- - ">="
|
|
139
140
|
- !ruby/object:Gem::Version
|
|
140
141
|
version: '0'
|
|
141
142
|
requirements: []
|
|
142
|
-
rubygems_version: 3.4.
|
|
143
|
+
rubygems_version: 3.4.10
|
|
143
144
|
signing_key:
|
|
144
145
|
specification_version: 4
|
|
145
146
|
summary: Simple manager for PostgreSQL objects like triggers and functions
|