pg_party 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2af92399978e7be5df6434c2f0dccf5896c5aa7
4
- data.tar.gz: 97721d501e40754098725a291c8fbdc2fcf6b14f
3
+ metadata.gz: f6b56b604caac2da35b9df72f1a43f1ac5464972
4
+ data.tar.gz: 468454403e514a160bdc8d4eaeb1f3c5cfdd324b
5
5
  SHA512:
6
- metadata.gz: 398c6ea0766a1e7c312f519b79906acbcc89a20ed83cc266940084a454ee50fe70fbe6bca096e0183291d6d1ad8bafd3345b37fd37a456e51a60c6532038145b
7
- data.tar.gz: 5254fd2f6b3b574eb76a9fc144d12a80e246718171ee38d5b240d214ae1d5dbdaeaec0436a5b5ddffbdd1388da312aea9dc0ce68abe8da5e2aee0ab091008d3c
6
+ metadata.gz: 2c5e035dbee595f7a77fc8312618164f8abc4b4958263c37d827b9b43667f67f212361cd1b26318d8701c3dde333f3024fd826a53f3b451a9cb51e27e233dea2
7
+ data.tar.gz: 196494724549d32744fdd76ff393a3afbf28d33b6db73219b275804b289fbe4dd847cb32bbb43e4be0a4c5b4e4973bd3c4db3d21b1570102b1e61b573e15d628
data/README.md CHANGED
@@ -189,7 +189,7 @@ SomeRangeRecord.partitions
189
189
  SomeListRecord.partitions
190
190
  ```
191
191
 
192
- Query for records by partition name:
192
+ Retrieve ActiveRecord model class scoped to a child partition:
193
193
 
194
194
  ```ruby
195
195
  SomeRangeRecord.in_partition(:some_range_records_partition_name)
@@ -140,8 +140,8 @@ module PgParty
140
140
  __getobj__.send(:postgresql_version) >= 100000
141
141
  end
142
142
 
143
- def index_name(table_name, partition_key)
144
- "index_#{table_name}_on_#{partition_key.to_s.split("::").join("_")}"
143
+ def index_name(table_name, key)
144
+ "index_#{table_name}_on_#{key.to_s.split("::").join("_")}"
145
145
  end
146
146
  end
147
147
  end
@@ -3,8 +3,8 @@ module PgParty
3
3
  def partition_primary_key
4
4
  if self != base_class
5
5
  base_class.primary_key
6
- elsif partition = partitions.first
7
- child_class(partition).get_primary_key(base_class.name)
6
+ elsif partition_name = partitions.first
7
+ in_partition(partition_name).get_primary_key(base_class.name)
8
8
  else
9
9
  get_primary_key(base_class.name)
10
10
  end
@@ -17,7 +17,26 @@ module PgParty
17
17
  end
18
18
 
19
19
  def in_partition(table_name)
20
- child_class(table_name).all
20
+ Class.new(__getobj__) do
21
+ self.table_name = table_name
22
+
23
+ # to avoid argument errors when calling model_name
24
+ def self.name
25
+ superclass.name
26
+ end
27
+
28
+ # when returning records from a query, Rails
29
+ # allocates objects first, then initializes
30
+ def self.allocate
31
+ superclass.allocate
32
+ end
33
+
34
+ # creating and persisting new records from a child partition
35
+ # will ultimately insert into the parent partition table
36
+ def self.new(*args, &blk)
37
+ superclass.new(*args, &blk)
38
+ end
39
+ end
21
40
  end
22
41
 
23
42
  def partition_key_eq(value)
@@ -73,24 +92,6 @@ module PgParty
73
92
  end
74
93
  end
75
94
 
76
- def child_class(table_name)
77
- Class.new(__getobj__) do
78
- self.table_name = table_name
79
-
80
- # when returning records from a query, Rails
81
- # allocates objects first, then initializes
82
- def self.allocate
83
- superclass.allocate
84
- end
85
-
86
- # not sure if this will ever get called,
87
- # but probably a good idea to have
88
- def self.new(*args, &blk)
89
- superclass.new(*args, &blk)
90
- end
91
- end
92
- end
93
-
94
95
  def partition_key_as_arel
95
96
  arel_column = arel_table[partition_column]
96
97
 
@@ -1,3 +1,3 @@
1
1
  module PgParty
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
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: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Krage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-15 00:00:00.000000000 Z
11
+ date: 2017-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  version: 1.8.11
240
240
  requirements: []
241
241
  rubyforge_project:
242
- rubygems_version: 2.4.5
242
+ rubygems_version: 2.6.11
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: ActiveRecord PostgreSQL Partitioning