pg_partitioner 0.5.4 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 483dd7d3b87cb8d5310dd9e03d78f0aa859caa841f34c35a52d629df13ebc5b8
4
- data.tar.gz: 8f80e4f358029ec9076ce61b711b4d8cf8ac668e8d2e3a2aae1c97ac11fdbfb4
3
+ metadata.gz: 5cfb29fd8934e56c5ede73e05b301f5fe56f638addfe8c8173475bc07fb54dcd
4
+ data.tar.gz: b0a9bb4f7183283fb979026ffb0f56478f2b17574efb4050fe502ca2d78ef59c
5
5
  SHA512:
6
- metadata.gz: 3429c1aef723f0f9c1c821f24970960b2957118ef7285df1d1d899eef53b252f662129c2db69d9ff09dacd1d042fba7387d0184b744eae1a91f0ade302d631c6
7
- data.tar.gz: d36715ab68ee3a2aca62c305f877a6ba2fbb292b9ec7cf2ddcb76864452fe9fff31bfe47747dae9b108442fab68f9c17b59ca0ff83a91efd4f68fdc2aa844079
6
+ metadata.gz: 2c541e52f227979b2dfc958f200d6dccb3bafec5fec4d96d6e0e48ccc75b31af385fea2897302d1a116a84025a093fb3f8c8a481df8334f3a1ba2eea65114122
7
+ data.tar.gz: 15086b751b086d43bff24cd7f4a01c7e5b1dfcb3f81370cdc81cd6d84dd2930e3e27e31ccae73d468c17b95abca58934394efe7293e6f321c451c1b27217cbf6
data/README.md CHANGED
@@ -53,6 +53,16 @@ class YourModelName < ActiveRecord::Base
53
53
  end
54
54
  end
55
55
  ```
56
+ Alternative usage of `partition_table_indexes` method. You can pass additional params to index creation with this way:
57
+ ```ruby
58
+ def self.partition_table_indexes
59
+ [
60
+ { fields: %w(column1 column2) },
61
+ { fields: %w(column1 column2 column3), name: 'my_index_for_column1_column2', unique: true },
62
+ { fields: %w(column1), where: 'user_id IS NOT NULL' }
63
+ ]
64
+ end
65
+ ```
56
66
  2) Create migration and add some instructions to it. Generate migration:
57
67
 
58
68
  ```
@@ -19,14 +19,20 @@ module PgPartitioner
19
19
  custom_indexes = partition_table_indexes.presence
20
20
  return unless custom_indexes
21
21
 
22
- custom_indexes.each { |custom_index| create_custom_index(partition_table_name, custom_index) }
22
+ custom_indexes.each do |custom_index|
23
+ if custom_index.is_a?(Hash)
24
+ create_custom_index(partition_table_name, custom_index[:fields], **custom_index.except(:fields))
25
+ else
26
+ create_custom_index(partition_table_name, custom_index)
27
+ end
28
+ end
23
29
  end
24
30
 
25
31
  def create_partition_named_indexes(partition_table_name)
26
32
  custom_indexes = partition_table_named_indexes.presence
27
33
  return unless custom_indexes
28
34
 
29
- custom_indexes.map do |name, custom_index|
35
+ custom_indexes.each do |name, custom_index|
30
36
  index_name = "index_#{partition_table_name}_#{name}"
31
37
  create_custom_named_index(partition_table_name, custom_index, index_name)
32
38
  end
@@ -36,16 +42,18 @@ module PgPartitioner
36
42
  custom_unique_indexes = partition_table_unique_indexes.presence
37
43
  return unless custom_unique_indexes
38
44
 
39
- custom_unique_indexes.each { |custom_index| create_custom_index(partition_table_name, custom_index, true) }
45
+ custom_unique_indexes.each do |custom_index|
46
+ create_custom_index(partition_table_name, custom_index, unique: true)
47
+ end
40
48
  end
41
49
 
42
50
  def create_partition_named_unique_indexes(partition_table_name)
43
51
  custom_indexes = partition_table_named_unique_indexes.presence
44
52
  return unless custom_indexes
45
53
 
46
- custom_indexes.map do |name, custom_index|
54
+ custom_indexes.each do |name, custom_index|
47
55
  index_name = "index_#{partition_table_name}_#{name}"
48
- create_custom_named_index(partition_table_name, custom_index, index_name, true)
56
+ create_custom_named_index(partition_table_name, custom_index, index_name, unique: true)
49
57
  end
50
58
  end
51
59
 
@@ -28,6 +28,7 @@ module PgPartitioner
28
28
  sql = "ALTER TABLE #{partition_table_name} ADD PRIMARY KEY (id);"
29
29
  execute_sql(sql)
30
30
 
31
+ disable_autovacuum(partition_table_name)
31
32
  create_partition_indexes(partition_table_name)
32
33
  create_partition_named_indexes(partition_table_name)
33
34
  create_partition_unique_indexes(partition_table_name)
@@ -22,6 +22,7 @@ module PgPartitioner
22
22
  sql = "ALTER TABLE #{partition_table_name} ADD PRIMARY KEY (id);"
23
23
  execute_sql(sql)
24
24
 
25
+ disable_autovacuum(partition_table_name)
25
26
  create_partition_indexes(partition_table_name)
26
27
  create_partition_named_indexes(partition_table_name)
27
28
  create_partition_unique_indexes(partition_table_name)
@@ -28,6 +28,7 @@ module PgPartitioner
28
28
  sql = "ALTER TABLE #{partition_table_name} ADD PRIMARY KEY (id);"
29
29
  execute_sql(sql)
30
30
 
31
+ disable_autovacuum(partition_table_name)
31
32
  create_partition_indexes(partition_table_name)
32
33
  create_partition_named_indexes(partition_table_name)
33
34
  create_partition_unique_indexes(partition_table_name)
@@ -1,3 +1,3 @@
1
1
  module PartitionerPg
2
- VERSION = '0.5.4'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -37,11 +37,15 @@ module PgPartitioner
37
37
  connection.execute(sql_string)
38
38
  end
39
39
 
40
- def create_custom_index(table_name, index_fields, is_unique = false)
41
- connection.add_index table_name, index_fields, unique: is_unique
40
+ def create_custom_index(table_name, index_fields, **keys)
41
+ connection.add_index(table_name, index_fields, **keys)
42
42
  end
43
43
 
44
- def create_custom_named_index(table_name, index_fields, name, is_unique = false)
45
- connection.add_index table_name, index_fields, name: name, unique: is_unique
44
+ def create_custom_named_index(table_name, index_fields, name, **keys)
45
+ connection.add_index(table_name, index_fields, name: name, **keys)
46
+ end
47
+
48
+ def disable_autovacuum(table_name)
49
+ execute_sql("ALTER TABLE #{table_name} SET (autovacuum_enabled = off);")
46
50
  end
47
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_partitioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ovsapyan Mishel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-02 00:00:00.000000000 Z
11
+ date: 2026-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.5.6
80
+ rubygems_version: 3.5.11
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Gem for a partitoning PG tables