active_partition 0.1.0 → 0.3.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: cd2f915d2a18fe45a1bfd5abada5f585341ee132a04c01a37214cd7a633ba7bd
4
+ data.tar.gz: dd8d0e55063e0acc1089cfc99c3de44e30c40f1b8ff4b99696c424407fd8aa7c
5
5
  SHA512:
6
- metadata.gz: 875150f22c67cbb6674b226517669c175685ee9132a5b60881f04763430ff2fcc328d0e5941b85d67240e3f88309737bed79ae1ff91036e2d32bfdb5ef061e41
7
- data.tar.gz: c6879e16a5b12532ceec50b23ef8571355bed9f922768d97e993b76b322b843802e5590b2de0be665bd12df6b431780c3241bcd4d7b70a8c2998487e3e436da6
6
+ metadata.gz: f32b271affea24e5c9d450c004fb094c2c18308e8370132754bf16444a16db0c21b75e72f2cf693c92ddbbc2cfad97ff4297495813f596996a9ee364fef15704
7
+ data.tar.gz: b18f0e4b19d116423ac3135797e68622eaaee93d0c1ea93f530282152606811cca395e156b516400e971427424897d3cd34f4eff49635774e6e24c20c131af00
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_partition (0.1.0)
4
+ active_partition (0.2.0)
5
5
  rails
6
6
  range_operators (~> 0.1.1)
7
7
  rspec-rails
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.3.0"
5
5
  end
@@ -14,9 +14,18 @@ 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_validation will be called with create, update, save, and create! methods
19
+ before_validation :create_partition_if_needed
18
20
 
19
21
  def create_partition_if_needed
22
+ if ["created_at", "updated_at"].include?(self.class.partitioned_by.to_s) && self.attributes[self.class.partitioned_by].nil?
23
+ # set default value if created_at or updated_at is nil
24
+ self.assign_attributes(self.class.partitioned_by => Time.current.utc)
25
+ end
26
+
27
+ return unless self.class.partitioned_by && attribute_changed?(self.class.partitioned_by.to_s)
28
+
20
29
  # get partitioned attribute value
21
30
  partitioned_value = attributes[self.class.partitioned_by.to_s]
22
31
  self.class.prepare_partition(partitioned_value, self.class.partition_range)
@@ -57,11 +66,11 @@ module ActivePartition
57
66
  end
58
67
  end
59
68
 
60
- delegate :premake, :latest_partition_coverage_time, to: :partition_manager
61
- delegate :retain, :retain_by_time, :retain_by_partition_count, to: :partition_manager
62
- delegate :prepare_partition, "active_partitions_cover?", to: :partition_manager
63
- delegate :get_all_supported_partition_tables, to: :partition_adapter
64
- delegate :drop_partition, to: :partition_adapter
69
+ # delegate :premake, :latest_partition_coverage_time, to: :partition_manager
70
+ # delegate :retain, :retain_by_time, :retain_by_partition_count, to: :partition_manager
71
+ # delegate :prepare_partition, "active_partitions_cover?", to: :partition_manager
72
+ # delegate :get_all_supported_partition_tables, to: :partition_adapter
73
+ # delegate :drop_partition, to: :partition_adapter
65
74
  end
66
75
  end
67
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thien Tran
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-01 00:00:00.000000000 Z
11
+ date: 2024-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug