active_partition 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/active_partition/version.rb +1 -1
- data/lib/active_partition.rb +9 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3178cd138ff766dfa2e7c01735724975fbaa1a63b0fb444c13643effd2b740d
|
4
|
+
data.tar.gz: 94d3d671b623d8f45ef95ad25023f84901653771a58fa764a7ce0364e386babb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53535fb5f2739bf8e6e3290e530e310dc80d7a3f6aeae71ee93c1ba88f56a22f9aaf2559a354a7c364604a3e2a8b03548e49317e68bb5d40946089c5ef43be61
|
7
|
+
data.tar.gz: 65037c3bcc0e9ed93f489670fd7377a35dfc67aac836b04c11b6e401d6010fe1098e410f090c7e2979443711aad506243a51d590be9211aff4156a893863b44a
|
data/Gemfile.lock
CHANGED
data/lib/active_partition.rb
CHANGED
@@ -15,12 +15,17 @@ module ActivePartition
|
|
15
15
|
|
16
16
|
included do
|
17
17
|
# when partitioned column change, create partition if needed
|
18
|
-
|
19
|
-
|
20
|
-
attribute_changed?(self.class.partitioned_by.to_s)
|
21
|
-
}
|
18
|
+
# before_validation will be called with create, update, save, and create! methods
|
19
|
+
before_validation :create_partition_if_needed
|
22
20
|
|
23
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
|
+
|
24
29
|
# get partitioned attribute value
|
25
30
|
partitioned_value = attributes[self.class.partitioned_by.to_s]
|
26
31
|
self.class.prepare_partition(partitioned_value, self.class.partition_range)
|
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.
|
4
|
+
version: 0.4.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-
|
11
|
+
date: 2024-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|