pg_party 1.6.0 → 1.7.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/README.md +12 -1
- data/lib/pg_party/adapter_decorator.rb +15 -13
- data/lib/pg_party/hacks/postgresql_database_tasks.rb +8 -7
- data/lib/pg_party/version.rb +1 -1
- metadata +13 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47b9e6d4d46ab349625ffcb49760675371e99412bdeac53993a7965dd08224cf
|
4
|
+
data.tar.gz: '08005f8354b7619a3e7745a67c157b2265851f0b7bc25568bfbd84d56e29a2b4'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6f5d302c2d4bdccc61ed263db7d04723551ab83bffdb1c89e229d8a602733329aa7568ff66ddcac7d4ffcf4a8c44ebd47536e3a50aa5f48a5876504224b8258
|
7
|
+
data.tar.gz: 0b5d15d2f46417a2a1eb54d56be0ba2b0a7c4a665c2c1b6ae38600891cb91260bb667f5d88cdd28b97d1b50370b4ce098ca895de3d8cdb2f58970aab474d76fc
|
data/README.md
CHANGED
@@ -21,9 +21,20 @@
|
|
21
21
|
|
22
22
|
- Partition tables are not represented correctly in `db/schema.rb` — please use the `:sql` schema format
|
23
23
|
|
24
|
+
## Compatibility
|
25
|
+
|
26
|
+
This gem is tested against:
|
27
|
+
|
28
|
+
- Rails: 6.1, 7.0, 7.1
|
29
|
+
- Ruby: 3.0, latest (currently 3.2 at the time of this commit)
|
30
|
+
- PostgreSQL: 11, 12, 13, 14, 15, 16
|
31
|
+
|
24
32
|
## Future Work
|
25
33
|
|
26
|
-
|
34
|
+
I plan to separate out the model functionality into a new gem and port the migration functionality into [pg\_ha\_migrations](https://github.com/braintree/pg_ha_migrations) (some of which has already been done).
|
35
|
+
I will continue to maintain this gem (bugfixes / support for new versions of Rails) until that work is complete.
|
36
|
+
|
37
|
+
I originally planned to add a feature for automatic partition creation, but I think that functionality would be better served by [pg\_partman](https://github.com/pgpartman/pg_partman).
|
27
38
|
|
28
39
|
## Installation
|
29
40
|
|
@@ -117,7 +117,7 @@ module PgParty
|
|
117
117
|
ON pg_tables.tablename::regclass = pg_inherits.inhparent::regclass
|
118
118
|
WHERE pg_tables.schemaname = current_schema() AND
|
119
119
|
pg_tables.tablename = #{quote(table_name)}
|
120
|
-
]).each_with_object(_accumulator) do |partition, acc|
|
120
|
+
], "SCHEMA").each_with_object(_accumulator) do |partition, acc|
|
121
121
|
acc << partition
|
122
122
|
next unless include_subpartitions
|
123
123
|
|
@@ -133,7 +133,7 @@ module PgParty
|
|
133
133
|
ON pg_tables.tablename::regclass = pg_inherits.inhrelid::regclass
|
134
134
|
WHERE pg_tables.schemaname = current_schema() AND
|
135
135
|
pg_tables.tablename = #{quote(table_name)}
|
136
|
-
]).first
|
136
|
+
], "SCHEMA").first
|
137
137
|
return parent if parent.nil? || !traverse
|
138
138
|
|
139
139
|
while (parents_parent = parent_for_table_name(parent)) do
|
@@ -174,12 +174,12 @@ module PgParty
|
|
174
174
|
SELECT relkind FROM pg_catalog.pg_class AS c
|
175
175
|
JOIN pg_catalog.pg_namespace AS ns ON c.relnamespace = ns.oid
|
176
176
|
WHERE relname = #{quote(table_name)} AND nspname = current_schema()
|
177
|
-
]).first == 'p'
|
177
|
+
], "SCHEMA").first == 'p'
|
178
178
|
end
|
179
179
|
|
180
180
|
private
|
181
181
|
|
182
|
-
def create_partition(table_name, type, partition_key, **options)
|
182
|
+
def create_partition(table_name, type, partition_key, **options, &blk)
|
183
183
|
modified_options = options.except(:id, :primary_key, :template, :create_with_primary_key)
|
184
184
|
template = options.fetch(:template, PgParty.config.create_template_tables)
|
185
185
|
id = options.fetch(:id, :bigserial)
|
@@ -200,18 +200,18 @@ module PgParty
|
|
200
200
|
end
|
201
201
|
modified_options[:options] = partition_by_clause(type, partition_key)
|
202
202
|
|
203
|
-
create_table(table_name, **modified_options) do |td|
|
203
|
+
migration_or_adapter(blk).create_table(table_name, **modified_options) do |td|
|
204
204
|
if !modified_options[:id] && id == :uuid
|
205
|
-
td.column(primary_key, id, null: false, default:
|
205
|
+
td.column(primary_key, id, null: false, default: "gen_random_uuid()")
|
206
206
|
elsif !modified_options[:id] && id
|
207
207
|
td.column(primary_key, id, null: false)
|
208
208
|
end
|
209
209
|
|
210
|
-
|
210
|
+
blk&.call(td)
|
211
211
|
end
|
212
212
|
|
213
213
|
# Rails 4 has a bug where uuid columns are always nullable
|
214
|
-
change_column_null(table_name, primary_key, false) if !modified_options[:id] && id == :uuid
|
214
|
+
migration_or_adapter(blk).change_column_null(table_name, primary_key, false) if !modified_options[:id] && id == :uuid
|
215
215
|
|
216
216
|
return unless template
|
217
217
|
|
@@ -410,10 +410,6 @@ module PgParty
|
|
410
410
|
"PARTITION BY #{type.to_s.upcase} (#{quote_partition_key(partition_key)})"
|
411
411
|
end
|
412
412
|
|
413
|
-
def uuid_function
|
414
|
-
try(:supports_pgcrypto_uuid?) ? "gen_random_uuid()" : "uuid_generate_v4()"
|
415
|
-
end
|
416
|
-
|
417
413
|
def hashed_table_name(table_name, key)
|
418
414
|
return "#{table_name}_#{Digest::MD5.hexdigest(key)[0..6]}" if key
|
419
415
|
|
@@ -424,7 +420,8 @@ module PgParty
|
|
424
420
|
def index_valid?(index_name)
|
425
421
|
select_values(
|
426
422
|
"SELECT relname FROM pg_class, pg_index WHERE pg_index.indisvalid = false AND "\
|
427
|
-
"pg_index.indexrelid = pg_class.oid AND relname = #{quote(index_name)}"
|
423
|
+
"pg_index.indexrelid = pg_class.oid AND relname = #{quote(index_name)}",
|
424
|
+
"SCHEMA"
|
428
425
|
).empty?
|
429
426
|
end
|
430
427
|
|
@@ -455,5 +452,10 @@ module PgParty
|
|
455
452
|
def postgres_major_version
|
456
453
|
__getobj__.send(:postgresql_version)/10000
|
457
454
|
end
|
455
|
+
|
456
|
+
def migration_or_adapter(blk)
|
457
|
+
blk_receiver = blk&.binding&.receiver
|
458
|
+
blk_receiver.is_a?(ActiveRecord::Migration) ? blk_receiver : self
|
459
|
+
end
|
458
460
|
end
|
459
461
|
end
|
@@ -8,13 +8,14 @@ module PgParty
|
|
8
8
|
return super
|
9
9
|
end
|
10
10
|
|
11
|
-
partitions =
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
partitions = ActiveRecord::Base.connection.select_values(<<-SQL, "SCHEMA")
|
12
|
+
SELECT
|
13
|
+
inhrelid::regclass::text
|
14
|
+
FROM
|
15
|
+
pg_inherits
|
16
|
+
JOIN pg_class AS p ON inhparent = p.oid
|
17
|
+
WHERE p.relkind = 'p'
|
18
|
+
SQL
|
18
19
|
|
19
20
|
excluded_tables = partitions.flat_map { |table| ["-T", "*.#{table}"] }
|
20
21
|
|
data/lib/pg_party/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_party
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Krage
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '7.
|
22
|
+
version: '7.2'
|
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: '
|
29
|
+
version: '6.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '7.
|
32
|
+
version: '7.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: ruby2_keywords
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,20 +100,6 @@ dependencies:
|
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '1.3'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: database_cleaner
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '1.7'
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - "~>"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '1.7'
|
117
103
|
- !ruby/object:Gem::Dependency
|
118
104
|
name: nokogiri
|
119
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,14 +168,14 @@ dependencies:
|
|
182
168
|
requirements:
|
183
169
|
- - "~>"
|
184
170
|
- !ruby/object:Gem::Version
|
185
|
-
version: '
|
171
|
+
version: '6.0'
|
186
172
|
type: :development
|
187
173
|
prerelease: false
|
188
174
|
version_requirements: !ruby/object:Gem::Requirement
|
189
175
|
requirements:
|
190
176
|
- - "~>"
|
191
177
|
- !ruby/object:Gem::Version
|
192
|
-
version: '
|
178
|
+
version: '6.0'
|
193
179
|
- !ruby/object:Gem::Dependency
|
194
180
|
name: rspec_junit_formatter
|
195
181
|
requirement: !ruby/object:Gem::Requirement
|
@@ -275,7 +261,7 @@ homepage: https://github.com/rkrage/pg_party
|
|
275
261
|
licenses:
|
276
262
|
- MIT
|
277
263
|
metadata: {}
|
278
|
-
post_install_message:
|
264
|
+
post_install_message:
|
279
265
|
rdoc_options: []
|
280
266
|
require_paths:
|
281
267
|
- lib
|
@@ -283,15 +269,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
283
269
|
requirements:
|
284
270
|
- - ">="
|
285
271
|
- !ruby/object:Gem::Version
|
286
|
-
version:
|
272
|
+
version: 3.0.0
|
287
273
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
288
274
|
requirements:
|
289
275
|
- - ">="
|
290
276
|
- !ruby/object:Gem::Version
|
291
277
|
version: '0'
|
292
278
|
requirements: []
|
293
|
-
rubygems_version: 3.
|
294
|
-
signing_key:
|
279
|
+
rubygems_version: 3.3.7
|
280
|
+
signing_key:
|
295
281
|
specification_version: 4
|
296
282
|
summary: ActiveRecord PostgreSQL Partitioning
|
297
283
|
test_files: []
|