pg_aggregates 0.2.1 → 0.2.3

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- pg_aggregates (0.1.1)
4
+ pg_aggregates (0.2.2)
5
5
  activerecord (>= 6.1)
6
6
  pg (>= 1.1)
7
7
  railties (>= 6.1)
@@ -9,9 +9,9 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (7.1.5)
13
- actionview (= 7.1.5)
14
- activesupport (= 7.1.5)
12
+ actionpack (7.1.5.1)
13
+ actionview (= 7.1.5.1)
14
+ activesupport (= 7.1.5.1)
15
15
  nokogiri (>= 1.8.5)
16
16
  racc
17
17
  rack (>= 2.2.4)
@@ -19,19 +19,19 @@ GEM
19
19
  rack-test (>= 0.6.3)
20
20
  rails-dom-testing (~> 2.2)
21
21
  rails-html-sanitizer (~> 1.6)
22
- actionview (7.1.5)
23
- activesupport (= 7.1.5)
22
+ actionview (7.1.5.1)
23
+ activesupport (= 7.1.5.1)
24
24
  builder (~> 3.1)
25
25
  erubi (~> 1.11)
26
26
  rails-dom-testing (~> 2.2)
27
27
  rails-html-sanitizer (~> 1.6)
28
- activemodel (7.1.5)
29
- activesupport (= 7.1.5)
30
- activerecord (7.1.5)
31
- activemodel (= 7.1.5)
32
- activesupport (= 7.1.5)
28
+ activemodel (7.1.5.1)
29
+ activesupport (= 7.1.5.1)
30
+ activerecord (7.1.5.1)
31
+ activemodel (= 7.1.5.1)
32
+ activesupport (= 7.1.5.1)
33
33
  timeout (>= 0.4.0)
34
- activesupport (7.1.5)
34
+ activesupport (7.1.5.1)
35
35
  base64
36
36
  benchmark (>= 0.3)
37
37
  bigdecimal
@@ -52,13 +52,13 @@ GEM
52
52
  bundler
53
53
  rake
54
54
  thor (>= 0.14.0)
55
- ast (2.4.2)
55
+ ast (2.4.3)
56
56
  base64 (0.2.0)
57
- benchmark (0.3.0)
58
- bigdecimal (3.1.8)
57
+ benchmark (0.4.0)
58
+ bigdecimal (3.1.9)
59
59
  builder (3.3.0)
60
- concurrent-ruby (1.3.4)
61
- connection_pool (2.4.1)
60
+ concurrent-ruby (1.3.5)
61
+ connection_pool (2.5.1)
62
62
  crass (1.0.6)
63
63
  database_cleaner (2.1.0)
64
64
  database_cleaner-active_record (>= 2, < 3)
@@ -66,61 +66,74 @@ GEM
66
66
  activerecord (>= 5.a)
67
67
  database_cleaner-core (~> 2.0.0)
68
68
  database_cleaner-core (2.0.1)
69
- diff-lcs (1.5.1)
69
+ date (3.4.1)
70
+ diff-lcs (1.6.1)
70
71
  drb (2.2.1)
71
- erubi (1.13.0)
72
- gem-release (2.2.2)
73
- i18n (1.14.6)
72
+ erubi (1.13.1)
73
+ gem-release (2.2.4)
74
+ i18n (1.14.7)
74
75
  concurrent-ruby (~> 1.0)
75
- io-console (0.7.2)
76
- irb (1.14.1)
76
+ io-console (0.8.0)
77
+ irb (1.15.2)
78
+ pp (>= 0.6.0)
77
79
  rdoc (>= 4.0.0)
78
80
  reline (>= 0.4.2)
79
- json (2.7.6)
80
- language_server-protocol (3.17.0.3)
81
- logger (1.6.1)
82
- loofah (2.23.1)
81
+ json (2.10.2)
82
+ language_server-protocol (3.17.0.4)
83
+ lint_roller (1.1.0)
84
+ logger (1.7.0)
85
+ loofah (2.24.0)
83
86
  crass (~> 1.0.2)
84
87
  nokogiri (>= 1.12.0)
85
- minitest (5.25.1)
86
- mutex_m (0.2.0)
87
- nokogiri (1.16.7-aarch64-linux)
88
+ minitest (5.25.5)
89
+ mutex_m (0.3.0)
90
+ nokogiri (1.18.7-aarch64-linux-gnu)
88
91
  racc (~> 1.4)
89
- nokogiri (1.16.7-arm-linux)
92
+ nokogiri (1.18.7-aarch64-linux-musl)
90
93
  racc (~> 1.4)
91
- nokogiri (1.16.7-arm64-darwin)
94
+ nokogiri (1.18.7-arm-linux-gnu)
92
95
  racc (~> 1.4)
93
- nokogiri (1.16.7-x86-linux)
96
+ nokogiri (1.18.7-arm-linux-musl)
94
97
  racc (~> 1.4)
95
- nokogiri (1.16.7-x86_64-darwin)
98
+ nokogiri (1.18.7-arm64-darwin)
96
99
  racc (~> 1.4)
97
- nokogiri (1.16.7-x86_64-linux)
100
+ nokogiri (1.18.7-x86_64-darwin)
98
101
  racc (~> 1.4)
99
- parallel (1.26.3)
100
- parser (3.3.5.1)
102
+ nokogiri (1.18.7-x86_64-linux-gnu)
103
+ racc (~> 1.4)
104
+ nokogiri (1.18.7-x86_64-linux-musl)
105
+ racc (~> 1.4)
106
+ parallel (1.27.0)
107
+ parser (3.3.8.0)
101
108
  ast (~> 2.4.1)
102
109
  racc
103
110
  pg (1.5.9)
104
- psych (5.1.2)
111
+ pp (0.6.2)
112
+ prettyprint
113
+ prettyprint (0.2.0)
114
+ prism (1.4.0)
115
+ psych (5.2.3)
116
+ date
105
117
  stringio
106
118
  racc (1.8.1)
107
- rack (3.1.8)
108
- rack-session (2.0.0)
119
+ rack (3.1.13)
120
+ rack-session (2.1.0)
121
+ base64 (>= 0.1.0)
109
122
  rack (>= 3.0.0)
110
- rack-test (2.1.0)
123
+ rack-test (2.2.0)
111
124
  rack (>= 1.3)
112
- rackup (2.2.0)
125
+ rackup (2.2.1)
113
126
  rack (>= 3)
114
127
  rails-dom-testing (2.2.0)
115
128
  activesupport (>= 5.0.0)
116
129
  minitest
117
130
  nokogiri (>= 1.6)
118
- rails-html-sanitizer (1.6.0)
131
+ rails-html-sanitizer (1.6.2)
119
132
  loofah (~> 2.21)
120
- nokogiri (~> 1.14)
121
- railties (7.1.5)
122
- actionpack (= 7.1.5)
123
- activesupport (= 7.1.5)
133
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
134
+ railties (7.1.5.1)
135
+ actionpack (= 7.1.5.1)
136
+ activesupport (= 7.1.5.1)
124
137
  irb
125
138
  rackup (>= 1.0.0)
126
139
  rake (>= 12.2)
@@ -128,16 +141,16 @@ GEM
128
141
  zeitwerk (~> 2.6)
129
142
  rainbow (3.1.1)
130
143
  rake (13.2.1)
131
- rdoc (6.7.0)
144
+ rdoc (6.13.1)
132
145
  psych (>= 4.0.0)
133
- regexp_parser (2.9.2)
134
- reline (0.5.10)
146
+ regexp_parser (2.10.0)
147
+ reline (0.6.1)
135
148
  io-console (~> 0.5)
136
149
  rspec (3.13.0)
137
150
  rspec-core (~> 3.13.0)
138
151
  rspec-expectations (~> 3.13.0)
139
152
  rspec-mocks (~> 3.13.0)
140
- rspec-core (3.13.2)
153
+ rspec-core (3.13.3)
141
154
  rspec-support (~> 3.13.0)
142
155
  rspec-expectations (3.13.3)
143
156
  diff-lcs (>= 1.2.0, < 2.0)
@@ -145,7 +158,7 @@ GEM
145
158
  rspec-mocks (3.13.2)
146
159
  diff-lcs (>= 1.2.0, < 2.0)
147
160
  rspec-support (~> 3.13.0)
148
- rspec-rails (7.0.1)
161
+ rspec-rails (7.1.1)
149
162
  actionpack (>= 7.0)
150
163
  activesupport (>= 7.0)
151
164
  railties (>= 7.0)
@@ -153,51 +166,52 @@ GEM
153
166
  rspec-expectations (~> 3.13)
154
167
  rspec-mocks (~> 3.13)
155
168
  rspec-support (~> 3.13)
156
- rspec-support (3.13.1)
157
- rubocop (1.68.0)
169
+ rspec-support (3.13.2)
170
+ rubocop (1.75.2)
158
171
  json (~> 2.3)
159
- language_server-protocol (>= 3.17.0)
172
+ language_server-protocol (~> 3.17.0.2)
173
+ lint_roller (~> 1.1.0)
160
174
  parallel (~> 1.10)
161
175
  parser (>= 3.3.0.2)
162
176
  rainbow (>= 2.2.2, < 4.0)
163
- regexp_parser (>= 2.4, < 3.0)
164
- rubocop-ast (>= 1.32.2, < 2.0)
177
+ regexp_parser (>= 2.9.3, < 3.0)
178
+ rubocop-ast (>= 1.44.0, < 2.0)
165
179
  ruby-progressbar (~> 1.7)
166
- unicode-display_width (>= 2.4.0, < 3.0)
167
- rubocop-ast (1.34.0)
168
- parser (>= 3.3.1.0)
169
- rubocop-mhenrixon (3.0.0)
170
- rubocop
171
- rubocop-performance
172
- rubocop-rake
173
- rubocop-rspec
174
- rubocop-thread_safety
175
- rubocop-performance (1.22.1)
176
- rubocop (>= 1.48.1, < 2.0)
177
- rubocop-ast (>= 1.31.1, < 2.0)
178
- rubocop-rake (0.6.0)
179
- rubocop (~> 1.0)
180
- rubocop-rspec (3.2.0)
181
- rubocop (~> 1.61)
182
- rubocop-thread_safety (0.5.1)
183
- rubocop (>= 0.90.0)
180
+ unicode-display_width (>= 2.4.0, < 4.0)
181
+ rubocop-ast (1.44.1)
182
+ parser (>= 3.3.7.2)
183
+ prism (~> 1.4)
184
+ rubocop-performance (1.25.0)
185
+ lint_roller (~> 1.1)
186
+ rubocop (>= 1.75.0, < 2.0)
187
+ rubocop-ast (>= 1.38.0, < 2.0)
188
+ rubocop-rake (0.7.1)
189
+ lint_roller (~> 1.1)
190
+ rubocop (>= 1.72.1)
191
+ rubocop-rspec (3.5.0)
192
+ lint_roller (~> 1.1)
193
+ rubocop (~> 1.72, >= 1.72.1)
184
194
  ruby-progressbar (1.13.0)
185
- securerandom (0.3.1)
186
- stringio (3.1.1)
195
+ securerandom (0.4.1)
196
+ stringio (3.1.6)
187
197
  thor (1.3.2)
188
- timeout (0.4.1)
198
+ timeout (0.4.3)
189
199
  tzinfo (2.0.6)
190
200
  concurrent-ruby (~> 1.0)
191
- unicode-display_width (2.6.0)
192
- zeitwerk (2.6.18)
201
+ unicode-display_width (3.1.4)
202
+ unicode-emoji (~> 4.0, >= 4.0.4)
203
+ unicode-emoji (4.0.4)
204
+ zeitwerk (2.7.2)
193
205
 
194
206
  PLATFORMS
195
- aarch64-linux
196
- arm-linux
207
+ aarch64-linux-gnu
208
+ aarch64-linux-musl
209
+ arm-linux-gnu
210
+ arm-linux-musl
197
211
  arm64-darwin
198
- x86-linux
199
212
  x86_64-darwin
200
- x86_64-linux
213
+ x86_64-linux-gnu
214
+ x86_64-linux-musl
201
215
 
202
216
  DEPENDENCIES
203
217
  activerecord (~> 7.1.0)
@@ -214,9 +228,10 @@ DEPENDENCIES
214
228
  railties (~> 7.1.0)
215
229
  rake
216
230
  rspec
217
- rubocop-mhenrixon
231
+ rubocop
232
+ rubocop-performance
218
233
  rubocop-rake
219
234
  rubocop-rspec
220
235
 
221
236
  BUNDLED WITH
222
- 2.5.20
237
+ 2.6.8
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by Appraisal
4
+
5
+ source "https://rubygems.org"
6
+
7
+ gem "activerecord", "~> 8.0.0"
8
+ gem "ammeter"
9
+ gem "appraisal"
10
+ gem "base64"
11
+ gem "bigdecimal"
12
+ gem "database_cleaner"
13
+ gem "drb"
14
+ gem "gem-release"
15
+ gem "logger"
16
+ gem "mutex_m"
17
+ gem "railties", "~> 8.0.0"
18
+ gem "rake"
19
+ gem "rspec"
20
+ gem "rubocop"
21
+ gem "rubocop-performance"
22
+ gem "rubocop-rake"
23
+ gem "rubocop-rspec"
24
+
25
+ gemspec path: "../"
@@ -0,0 +1,239 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ pg_aggregates (0.2.2)
5
+ activerecord (>= 6.1)
6
+ pg (>= 1.1)
7
+ railties (>= 6.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionpack (8.0.2)
13
+ actionview (= 8.0.2)
14
+ activesupport (= 8.0.2)
15
+ nokogiri (>= 1.8.5)
16
+ rack (>= 2.2.4)
17
+ rack-session (>= 1.0.1)
18
+ rack-test (>= 0.6.3)
19
+ rails-dom-testing (~> 2.2)
20
+ rails-html-sanitizer (~> 1.6)
21
+ useragent (~> 0.16)
22
+ actionview (8.0.2)
23
+ activesupport (= 8.0.2)
24
+ builder (~> 3.1)
25
+ erubi (~> 1.11)
26
+ rails-dom-testing (~> 2.2)
27
+ rails-html-sanitizer (~> 1.6)
28
+ activemodel (8.0.2)
29
+ activesupport (= 8.0.2)
30
+ activerecord (8.0.2)
31
+ activemodel (= 8.0.2)
32
+ activesupport (= 8.0.2)
33
+ timeout (>= 0.4.0)
34
+ activesupport (8.0.2)
35
+ base64
36
+ benchmark (>= 0.3)
37
+ bigdecimal
38
+ concurrent-ruby (~> 1.0, >= 1.3.1)
39
+ connection_pool (>= 2.2.5)
40
+ drb
41
+ i18n (>= 1.6, < 2)
42
+ logger (>= 1.4.2)
43
+ minitest (>= 5.1)
44
+ securerandom (>= 0.3)
45
+ tzinfo (~> 2.0, >= 2.0.5)
46
+ uri (>= 0.13.1)
47
+ ammeter (1.1.7)
48
+ activesupport (>= 3.0)
49
+ railties (>= 3.0)
50
+ rspec-rails (>= 2.2)
51
+ appraisal (2.5.0)
52
+ bundler
53
+ rake
54
+ thor (>= 0.14.0)
55
+ ast (2.4.3)
56
+ base64 (0.2.0)
57
+ benchmark (0.4.0)
58
+ bigdecimal (3.1.9)
59
+ builder (3.3.0)
60
+ concurrent-ruby (1.3.5)
61
+ connection_pool (2.5.1)
62
+ crass (1.0.6)
63
+ database_cleaner (2.1.0)
64
+ database_cleaner-active_record (>= 2, < 3)
65
+ database_cleaner-active_record (2.2.0)
66
+ activerecord (>= 5.a)
67
+ database_cleaner-core (~> 2.0.0)
68
+ database_cleaner-core (2.0.1)
69
+ date (3.4.1)
70
+ diff-lcs (1.6.1)
71
+ drb (2.2.1)
72
+ erubi (1.13.1)
73
+ gem-release (2.2.4)
74
+ i18n (1.14.7)
75
+ concurrent-ruby (~> 1.0)
76
+ io-console (0.8.0)
77
+ irb (1.15.2)
78
+ pp (>= 0.6.0)
79
+ rdoc (>= 4.0.0)
80
+ reline (>= 0.4.2)
81
+ json (2.10.2)
82
+ language_server-protocol (3.17.0.4)
83
+ lint_roller (1.1.0)
84
+ logger (1.7.0)
85
+ loofah (2.24.0)
86
+ crass (~> 1.0.2)
87
+ nokogiri (>= 1.12.0)
88
+ minitest (5.25.5)
89
+ mutex_m (0.3.0)
90
+ nokogiri (1.18.7-aarch64-linux-gnu)
91
+ racc (~> 1.4)
92
+ nokogiri (1.18.7-aarch64-linux-musl)
93
+ racc (~> 1.4)
94
+ nokogiri (1.18.7-arm-linux-gnu)
95
+ racc (~> 1.4)
96
+ nokogiri (1.18.7-arm-linux-musl)
97
+ racc (~> 1.4)
98
+ nokogiri (1.18.7-arm64-darwin)
99
+ racc (~> 1.4)
100
+ nokogiri (1.18.7-x86_64-darwin)
101
+ racc (~> 1.4)
102
+ nokogiri (1.18.7-x86_64-linux-gnu)
103
+ racc (~> 1.4)
104
+ nokogiri (1.18.7-x86_64-linux-musl)
105
+ racc (~> 1.4)
106
+ parallel (1.27.0)
107
+ parser (3.3.8.0)
108
+ ast (~> 2.4.1)
109
+ racc
110
+ pg (1.5.9)
111
+ pp (0.6.2)
112
+ prettyprint
113
+ prettyprint (0.2.0)
114
+ prism (1.4.0)
115
+ psych (5.2.3)
116
+ date
117
+ stringio
118
+ racc (1.8.1)
119
+ rack (3.1.13)
120
+ rack-session (2.1.0)
121
+ base64 (>= 0.1.0)
122
+ rack (>= 3.0.0)
123
+ rack-test (2.2.0)
124
+ rack (>= 1.3)
125
+ rackup (2.2.1)
126
+ rack (>= 3)
127
+ rails-dom-testing (2.2.0)
128
+ activesupport (>= 5.0.0)
129
+ minitest
130
+ nokogiri (>= 1.6)
131
+ rails-html-sanitizer (1.6.2)
132
+ loofah (~> 2.21)
133
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
134
+ railties (8.0.2)
135
+ actionpack (= 8.0.2)
136
+ activesupport (= 8.0.2)
137
+ irb (~> 1.13)
138
+ rackup (>= 1.0.0)
139
+ rake (>= 12.2)
140
+ thor (~> 1.0, >= 1.2.2)
141
+ zeitwerk (~> 2.6)
142
+ rainbow (3.1.1)
143
+ rake (13.2.1)
144
+ rdoc (6.13.1)
145
+ psych (>= 4.0.0)
146
+ regexp_parser (2.10.0)
147
+ reline (0.6.1)
148
+ io-console (~> 0.5)
149
+ rspec (3.13.0)
150
+ rspec-core (~> 3.13.0)
151
+ rspec-expectations (~> 3.13.0)
152
+ rspec-mocks (~> 3.13.0)
153
+ rspec-core (3.13.3)
154
+ rspec-support (~> 3.13.0)
155
+ rspec-expectations (3.13.3)
156
+ diff-lcs (>= 1.2.0, < 2.0)
157
+ rspec-support (~> 3.13.0)
158
+ rspec-mocks (3.13.2)
159
+ diff-lcs (>= 1.2.0, < 2.0)
160
+ rspec-support (~> 3.13.0)
161
+ rspec-rails (7.1.1)
162
+ actionpack (>= 7.0)
163
+ activesupport (>= 7.0)
164
+ railties (>= 7.0)
165
+ rspec-core (~> 3.13)
166
+ rspec-expectations (~> 3.13)
167
+ rspec-mocks (~> 3.13)
168
+ rspec-support (~> 3.13)
169
+ rspec-support (3.13.2)
170
+ rubocop (1.75.2)
171
+ json (~> 2.3)
172
+ language_server-protocol (~> 3.17.0.2)
173
+ lint_roller (~> 1.1.0)
174
+ parallel (~> 1.10)
175
+ parser (>= 3.3.0.2)
176
+ rainbow (>= 2.2.2, < 4.0)
177
+ regexp_parser (>= 2.9.3, < 3.0)
178
+ rubocop-ast (>= 1.44.0, < 2.0)
179
+ ruby-progressbar (~> 1.7)
180
+ unicode-display_width (>= 2.4.0, < 4.0)
181
+ rubocop-ast (1.44.1)
182
+ parser (>= 3.3.7.2)
183
+ prism (~> 1.4)
184
+ rubocop-performance (1.25.0)
185
+ lint_roller (~> 1.1)
186
+ rubocop (>= 1.75.0, < 2.0)
187
+ rubocop-ast (>= 1.38.0, < 2.0)
188
+ rubocop-rake (0.7.1)
189
+ lint_roller (~> 1.1)
190
+ rubocop (>= 1.72.1)
191
+ rubocop-rspec (3.5.0)
192
+ lint_roller (~> 1.1)
193
+ rubocop (~> 1.72, >= 1.72.1)
194
+ ruby-progressbar (1.13.0)
195
+ securerandom (0.4.1)
196
+ stringio (3.1.6)
197
+ thor (1.3.2)
198
+ timeout (0.4.3)
199
+ tzinfo (2.0.6)
200
+ concurrent-ruby (~> 1.0)
201
+ unicode-display_width (3.1.4)
202
+ unicode-emoji (~> 4.0, >= 4.0.4)
203
+ unicode-emoji (4.0.4)
204
+ uri (1.0.3)
205
+ useragent (0.16.11)
206
+ zeitwerk (2.7.2)
207
+
208
+ PLATFORMS
209
+ aarch64-linux-gnu
210
+ aarch64-linux-musl
211
+ arm-linux-gnu
212
+ arm-linux-musl
213
+ arm64-darwin
214
+ x86_64-darwin
215
+ x86_64-linux-gnu
216
+ x86_64-linux-musl
217
+
218
+ DEPENDENCIES
219
+ activerecord (~> 8.0.0)
220
+ ammeter
221
+ appraisal
222
+ base64
223
+ bigdecimal
224
+ database_cleaner
225
+ drb
226
+ gem-release
227
+ logger
228
+ mutex_m
229
+ pg_aggregates!
230
+ railties (~> 8.0.0)
231
+ rake
232
+ rspec
233
+ rubocop
234
+ rubocop-performance
235
+ rubocop-rake
236
+ rubocop-rspec
237
+
238
+ BUNDLED WITH
239
+ 2.6.8
@@ -2,11 +2,9 @@
2
2
 
3
3
  module PgAggregates
4
4
  class Railtie < Rails::Railtie
5
- initializer "postgres_aggregates.load" do
5
+ initializer "pg_aggregates.load", before: "fx.load" do
6
6
  ActiveSupport.on_load(:active_record) do
7
- ActiveRecord::ConnectionAdapters::AbstractAdapter.include PgAggregates::SchemaStatements
8
- ActiveRecord::Migration::CommandRecorder.include PgAggregates::CommandRecorder
9
- ActiveRecord::SchemaDumper.prepend PgAggregates::SchemaDumper
7
+ PgAggregates.load
10
8
  end
11
9
  end
12
10
  end
@@ -1,50 +1,90 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ostruct"
4
+
3
5
  module PgAggregates
4
6
  module SchemaDumper
5
- def tables(stream)
6
- super
7
+ # Define a Struct for aggregate information
8
+ AggregateDefinition = Struct.new(:name, :definition)
7
9
 
8
- # First dump aggregates
10
+ # Override the tables method to inject aggregate dumping *after* functions (handled by fx)
11
+ # but *before* tables.
12
+ def tables(stream)
13
+ # Dump custom aggregates first
9
14
  dump_custom_aggregates(stream)
10
- stream.puts
15
+
16
+ stream.puts # Add a newline for separation before tables
17
+
18
+ # Call the next implementation (likely fx's tables or Rails' tables)
19
+ super
11
20
  end
12
21
 
13
22
  private
14
23
 
15
24
  def dump_custom_aggregates(stream)
16
- # Group all versions of each aggregate
17
- aggregate_versions = {}
18
-
19
- Dir.glob(Rails.root.join("db/aggregates/*_v*.sql").to_s).each do |file|
20
- file_version = FileVersion.new(file)
21
- aggregate_versions[file_version.name] ||= []
22
- aggregate_versions[file_version.name] << file_version
23
- end
25
+ aggregates = dumpable_aggregates_in_database
24
26
 
25
- return if aggregate_versions.empty?
27
+ return if aggregates.empty?
26
28
 
27
29
  stream.puts " # These are custom PostgreSQL aggregates that were defined"
28
30
 
29
- # For each aggregate, use the latest version
30
- latest_versions = aggregate_versions.transform_values do |versions|
31
- versions.max_by(&:version)
32
- end
33
-
34
31
  # Sort by name to ensure consistent ordering
35
- latest_versions.keys.sort.each do |aggregate_name|
36
- file_version = latest_versions[aggregate_name]
32
+ aggregates.sort_by(&:name).each do |aggregate|
33
+ stream.puts <<~AGG
34
+ create_aggregate "#{aggregate.name}", sql_definition: <<-SQL
35
+ #{aggregate.definition}
36
+ SQL
37
+
38
+ AGG
39
+ end
40
+ end
37
41
 
38
- # Add a comment showing the version history
39
- all_versions = aggregate_versions[aggregate_name].map(&:version).sort
40
- version_comment = all_versions.size > 1 ? " -- versions: #{all_versions.join(", ")}" : ""
42
+ # Fetches all aggregate functions from the database
43
+ def dumpable_aggregates_in_database
44
+ @dumpable_aggregates_in_database ||= begin
45
+ # SQL query to fetch aggregate functions from PostgreSQL
46
+ # This query gets the aggregate name and constructs the CREATE AGGREGATE statement
47
+ sql = <<~SQL
48
+ SELECT
49
+ p.proname AS name,
50
+ format(
51
+ 'CREATE AGGREGATE %s(%s) (%s);',
52
+ p.proname,
53
+ pg_get_function_arguments(p.oid),
54
+ array_to_string(array_agg(format('%s = %s', option_name, option_value)), E',\n ')
55
+ ) AS definition
56
+ FROM pg_proc p
57
+ JOIN pg_namespace n ON p.pronamespace = n.oid
58
+ JOIN pg_aggregate a ON a.aggfnoid = p.oid
59
+ JOIN LATERAL (
60
+ SELECT 'sfunc' AS option_name, p2.proname::text AS option_value
61
+ FROM pg_proc p2
62
+ WHERE p2.oid = a.aggtransfn
63
+ UNION ALL
64
+ SELECT 'stype', format_type(a.aggtranstype, NULL)
65
+ UNION ALL
66
+ SELECT 'finalfunc', p3.proname::text
67
+ FROM pg_proc p3
68
+ WHERE p3.oid = a.aggfinalfn AND a.aggfinalfn != 0
69
+ UNION ALL
70
+ SELECT 'initcond', quote_literal(a.agginitval)
71
+ WHERE a.agginitval IS NOT NULL
72
+ ) options ON true
73
+ WHERE n.nspname = 'public'
74
+ GROUP BY p.proname, p.oid
75
+ ORDER BY p.proname;
76
+ SQL
41
77
 
42
- stream.puts <<-AGG
43
- create_aggregate "#{aggregate_name}", sql_definition: <<-SQL#{version_comment}
44
- #{file_version.sql_definition}
45
- SQL
78
+ # Get the appropriate connection
79
+ connection = ActiveRecord::Base.connection
46
80
 
47
- AGG
81
+ # Execute the query and transform results into aggregate objects
82
+ connection.execute(sql).map do |result|
83
+ AggregateDefinition.new(
84
+ result["name"],
85
+ result["definition"].strip
86
+ )
87
+ end
48
88
  end
49
89
  end
50
90
  end