pg_party 0.3.0 → 0.4.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: 820e7b5d4a74330f2871d8e8d5e278974001dd1f
4
- data.tar.gz: 80a59da979fa45c339aa3abe0201c154809a4eb4
3
+ metadata.gz: 559a9b103f19cf52a702be11bb98bd0df55935d7
4
+ data.tar.gz: 3b25f89a601b7f3898fc3de9e901ff021ff97faa
5
5
  SHA512:
6
- metadata.gz: 4e14b35c529df6ea91d093e444962be64d65a112ab706b67bdce500904fb74eb88c31fd944aa06c9386f8cd365286841723ea71ecb883086604912ce6484d6db
7
- data.tar.gz: 622f8c66614c01ef3a2a649f6e0c9123b07a7d73d8adbd74ef2428215ff70d78a70e554f5bd4b98e246beb2327d174b5badce0131d6127c19b59234f9bf10022
6
+ metadata.gz: c51bf8b2a408e2167cdbcd61c8e2ee2b8ab259a63017747cad56959a7f7be11504034845bb6b92e383fb7b3abf18082658b449d721619e537ba92a948ededbb4
7
+ data.tar.gz: 3c4e20e4171bc302a8bd5d2bc4f35bf33b20f4f80ddcf31d256384be02c31cd4d9d3039eba088a37c7edab7d4d92825036627c1d6409ca956f5da6bce4d7ab0a
data/README.md CHANGED
@@ -8,15 +8,13 @@
8
8
  [circle]: https://circleci.com/gh/rkrage/pg_party
9
9
  [climate]: https://codeclimate.com/github/rkrage/pg_party
10
10
 
11
- [Active Record](http://guides.rubyonrails.org/active_record_basics.html) migrations and model helpers for creating and managing [PostgreSQL 10 partitions](https://www.postgresql.org/docs/10/static/ddl-partitioning.html)!
11
+ [ActiveRecord](http://guides.rubyonrails.org/active_record_basics.html) migrations and model helpers for creating and managing [PostgreSQL 10 partitions](https://www.postgresql.org/docs/10/static/ddl-partitioning.html)!
12
12
 
13
13
  Features:
14
14
  - migration methods for partition specific database operations
15
15
  - model methods for querying partitioned data
16
16
  - model methods for creating adhoc partitions
17
17
 
18
- Note: PostgreSQL 10 is currently in beta. This gem should not be used in production environments (yet).
19
-
20
18
  ## Installation
21
19
 
22
20
  Add this line to your application's Gemfile:
@@ -98,7 +96,7 @@ Attach an existing table to a range partition:
98
96
  ```ruby
99
97
  class AttachRangePartition < ActiveRecord::Migration[5.1]
100
98
  def up
101
- attach_range_partition("parent_table", "child_table")
99
+ attach_range_partition(:parent_table, :child_table)
102
100
  end
103
101
  end
104
102
  ```
@@ -108,7 +106,7 @@ Attach an existing table to a list partition:
108
106
  ```ruby
109
107
  class AttachListPartition < ActiveRecord::Migration[5.1]
110
108
  def up
111
- attach_list_partition("parent_table", "child_table")
109
+ attach_list_partition(:parent_table, :child_table)
112
110
  end
113
111
  end
114
112
  ```
@@ -118,7 +116,7 @@ Detach a child table from any partition:
118
116
  ```ruby
119
117
  class DetachPartition < ActiveRecord::Migration[5.1]
120
118
  def up
121
- detach_partition("parent_table", "child_table")
119
+ detach_partition(:parent_table, :child_table)
122
120
  end
123
121
  end
124
122
  ```
@@ -175,14 +173,22 @@ SomeRangeRecord.partition_key_eq(Date.current)
175
173
  SomeListRecord.partition_key_eq(100)
176
174
  ```
177
175
 
176
+ List currently attached partitions:
177
+
178
+ ```ruby
179
+ SomeRangeRecord.partitions
180
+
181
+ SomeListRecord.partitions
182
+ ```
183
+
178
184
  Query for records by partition name:
179
185
 
180
186
  ```ruby
181
187
  # returns a collection of anonymous ActiveRecord::Base subclassed instances
182
- SomeRangeRecord.in_partition("some_range_records_partition_name")
188
+ SomeRangeRecord.in_partition(:some_range_records_partition_name)
183
189
 
184
190
  # returns a collection of anonymous ActiveRecord::Base subclassed instances
185
- SomeListRecord.in_partition("some_list_records_partition_name")
191
+ SomeListRecord.in_partition(:some_list_records_partition_name)
186
192
  ```
187
193
 
188
194
  ## Development
@@ -200,7 +206,7 @@ Install dependencies:
200
206
 
201
207
  Run the tests:
202
208
 
203
- $ bin/de rake
209
+ $ bin/de appraisal rake
204
210
 
205
211
  Open a Pry console to play around with the sample Rails app:
206
212
 
@@ -7,17 +7,9 @@ module PgParty
7
7
  PgParty::ModelDecorator.new(self).create_list_partition(*args)
8
8
  end
9
9
 
10
- def in_partition(*args)
11
- PgParty::ModelDecorator.new(self).in_partition(*args)
12
- end
13
-
14
10
  def partition_key_in(*args)
15
11
  PgParty::ModelDecorator.new(self).list_partition_key_in(*args)
16
12
  end
17
-
18
- def partition_key_eq(*args)
19
- PgParty::ModelDecorator.new(self).partition_key_eq(*args)
20
- end
21
13
  end
22
14
  end
23
15
  end
@@ -7,17 +7,9 @@ module PgParty
7
7
  PgParty::ModelDecorator.new(self).create_range_partition(*args)
8
8
  end
9
9
 
10
- def in_partition(*args)
11
- PgParty::ModelDecorator.new(self).in_partition(*args)
12
- end
13
-
14
10
  def partition_key_in(*args)
15
11
  PgParty::ModelDecorator.new(self).range_partition_key_in(*args)
16
12
  end
17
-
18
- def partition_key_eq(*args)
19
- PgParty::ModelDecorator.new(self).partition_key_eq(*args)
20
- end
21
13
  end
22
14
  end
23
15
  end
@@ -0,0 +1,27 @@
1
+ require "pg_party/model_decorator"
2
+
3
+ module PgParty
4
+ module Model
5
+ module SharedMethods
6
+ def partitions
7
+ PgParty::ModelDecorator.new(self).partitions
8
+ end
9
+
10
+ def create_partition(*args)
11
+ PgParty::ModelDecorator.new(self).create_list_partition(*args)
12
+ end
13
+
14
+ def in_partition(*args)
15
+ PgParty::ModelDecorator.new(self).in_partition(*args)
16
+ end
17
+
18
+ def partition_key_in(*args)
19
+ PgParty::ModelDecorator.new(self).list_partition_key_in(*args)
20
+ end
21
+
22
+ def partition_key_eq(*args)
23
+ PgParty::ModelDecorator.new(self).partition_key_eq(*args)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -18,6 +18,16 @@ module PgParty
18
18
  where(partition_key_as_arel.in(values.flatten))
19
19
  end
20
20
 
21
+ def partitions
22
+ connection.select_values(<<-SQL)
23
+ SELECT pg_inherits.inhrelid::regclass::text
24
+ FROM pg_tables
25
+ INNER JOIN pg_inherits
26
+ ON pg_tables.tablename::regclass = pg_inherits.inhparent::regclass
27
+ WHERE pg_tables.tablename = #{connection.quote(table_name)}
28
+ SQL
29
+ end
30
+
21
31
  def create_range_partition(start_range:, end_range:, **options)
22
32
  modified_options = options.merge(
23
33
  start_range: start_range,
@@ -8,21 +8,28 @@ module PgParty
8
8
  end
9
9
 
10
10
  def inject_range_methods
11
- create_class_attributes
12
-
13
11
  require "pg_party/model/range_methods"
14
- @model.extend(PgParty::Model::RangeMethods)
12
+
13
+ inject_methods_for(PgParty::Model::RangeMethods)
15
14
  end
16
15
 
17
16
  def inject_list_methods
18
- create_class_attributes
19
-
20
17
  require "pg_party/model/list_methods"
21
- @model.extend(PgParty::Model::ListMethods)
18
+
19
+ inject_methods_for(PgParty::Model::ListMethods)
22
20
  end
23
21
 
24
22
  private
25
23
 
24
+ def inject_methods_for(mod)
25
+ require "pg_party/model/shared_methods"
26
+
27
+ @model.extend(PgParty::Model::SharedMethods)
28
+ @model.extend(mod)
29
+
30
+ create_class_attributes
31
+ end
32
+
26
33
  def create_class_attributes
27
34
  @model.class_attribute(
28
35
  :partition_key,
@@ -1,3 +1,3 @@
1
1
  module PgParty
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.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.3.0
4
+ version: 0.4.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-09-29 00:00:00.000000000 Z
11
+ date: 2017-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -195,6 +195,7 @@ files:
195
195
  - lib/pg_party/model/list_methods.rb
196
196
  - lib/pg_party/model/methods.rb
197
197
  - lib/pg_party/model/range_methods.rb
198
+ - lib/pg_party/model/shared_methods.rb
198
199
  - lib/pg_party/model_decorator.rb
199
200
  - lib/pg_party/model_injector.rb
200
201
  - lib/pg_party/version.rb
@@ -218,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
219
  version: 1.8.11
219
220
  requirements: []
220
221
  rubyforge_project:
221
- rubygems_version: 2.6.11
222
+ rubygems_version: 2.4.5
222
223
  signing_key:
223
224
  specification_version: 4
224
225
  summary: ActiveRecord PostgreSQL Partitioning