active_partition 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 864c367836794df12bbca3d03d7a957399930f6532ce06880bcc1e63adf49adb
4
- data.tar.gz: 4e8a7e5031450b879921cba8b1cbf65f3aa1ddbfc6ad7d8af3746f67c14f7587
3
+ metadata.gz: 2f9a675008e38b58080b6c3e350a2141be7275e5ca153500340a1f0f759e1442
4
+ data.tar.gz: 58a64de3dd865b634baf1fd3999203c75f4007d046e68818ab92c382b6c54b98
5
5
  SHA512:
6
- metadata.gz: 875150f22c67cbb6674b226517669c175685ee9132a5b60881f04763430ff2fcc328d0e5941b85d67240e3f88309737bed79ae1ff91036e2d32bfdb5ef061e41
7
- data.tar.gz: c6879e16a5b12532ceec50b23ef8571355bed9f922768d97e993b76b322b843802e5590b2de0be665bd12df6b431780c3241bcd4d7b70a8c2998487e3e436da6
6
+ metadata.gz: 180a0215bb89ef08a3fb3ab38490ad89335419ec9fd1b4026026ef008e1fefcd02dc4ccfcb8e9c0e16c231aa7193119d32520b1fe87cd70e0448a613fb1871f1
7
+ data.tar.gz: 2e014eabe0b6b129f062ac5c7341b4819fc87e9e5206479b6b3630945b8b220bfd2a0c30591ab44b7f23b982829dd0dcb5714215ac962384311efc490c57a862
data/bin/console CHANGED
@@ -21,6 +21,7 @@ end
21
21
  # Create test model
22
22
  class OutgoingEvent < ActiveRecord::Base
23
23
  include ActivePartition::Partitionable
24
+ self.primary_key = "id"
24
25
  self.partitioned_by = "created_at"
25
26
  self.partition_range = 1.day
26
27
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivePartition
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -14,7 +14,11 @@ module ActivePartition
14
14
  extend ActiveSupport::Concern
15
15
 
16
16
  included do
17
- before_create :create_partition_if_needed
17
+ # when partitioned column change, create partition if needed
18
+ before_save :create_partition_if_needed, if: -> {
19
+ self.class.partitioned_by &&
20
+ attribute_changed?(self.class.partitioned_by.to_s)
21
+ }
18
22
 
19
23
  def create_partition_if_needed
20
24
  # get partitioned attribute value
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_partition
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thien Tran