active_partition 0.4.0 → 0.5.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: c3178cd138ff766dfa2e7c01735724975fbaa1a63b0fb444c13643effd2b740d
4
- data.tar.gz: 94d3d671b623d8f45ef95ad25023f84901653771a58fa764a7ce0364e386babb
3
+ metadata.gz: 9c038362292769cc7d68786d177c845429a6e15a3bac8c6b1de166e976a27d26
4
+ data.tar.gz: 84a4f14e03c642cd562caae6e93fd9aaee1a4bf2bb7e4bb50f284860a809e2fa
5
5
  SHA512:
6
- metadata.gz: 53535fb5f2739bf8e6e3290e530e310dc80d7a3f6aeae71ee93c1ba88f56a22f9aaf2559a354a7c364604a3e2a8b03548e49317e68bb5d40946089c5ef43be61
7
- data.tar.gz: 65037c3bcc0e9ed93f489670fd7377a35dfc67aac836b04c11b6e401d6010fe1098e410f090c7e2979443711aad506243a51d590be9211aff4156a893863b44a
6
+ metadata.gz: 9d15088d3d42bb257b854e7f04ed265400ae810831692b5fda3f5ef8ae2d7e3582bf09e7703393e2cbdf67cdf388b74a6b1dd77624a74a38706f9face93ac3d1
7
+ data.tar.gz: 0a58ffcebd2c11bc4e26faefe7106928ef58fa435c7d8c7e441b11b06487f018298cfcceec3fb8d924ac80a62f1d4a844f8c381a736930f6a583bcc9f334d30d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_partition (0.2.0)
4
+ active_partition (0.4.0)
5
5
  rails
6
6
  range_operators (~> 0.1.1)
7
7
  rspec-rails
data/bin/console CHANGED
@@ -30,7 +30,31 @@ class OutgoingEvent < ActiveRecord::Base
30
30
  self.retention_partition_count = 3
31
31
  end
32
32
 
33
+ class OutgoingEventsWebhook < ActiveRecord::Base
34
+ include ActivePartition::Partitionable
35
+ self.primary_key = "id"
36
+ self.partitioned_by = "created_at"
37
+ self.partition_range = 1.hour
38
+
39
+ # You can choose 1 of the following 2 options
40
+ self.retention_period = 1.day
41
+ self.retention_partition_count = 3
42
+ end
43
+
33
44
  OutgoingEvent.establish_connection(ENV["DATABASE_URL"])
45
+ OutgoingEventsWebhook.establish_connection(ENV["DATABASE_URL"])
46
+
47
+ if OutgoingEventsWebhook.partition_adapter == OutgoingEvent.partition_adapter
48
+ puts "Violate the partition adapter constraint", OutgoingEventsWebhook.partition_adapter == OutgoingEvent.partition_adapter
49
+ puts OutgoingEventsWebhook.partition_adapter
50
+ puts OutgoingEvent.partition_adapter
51
+ end
52
+
53
+ if OutgoingEventsWebhook.partition_manager == OutgoingEvent.partition_manager
54
+ puts "Violate the partition manager constraint"
55
+ puts OutgoingEventsWebhook.partition_manager
56
+ puts OutgoingEvent.partition_manager
57
+ end
34
58
 
35
59
  require "irb"
36
60
  IRB.start(__FILE__)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivePartition
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -13,6 +13,7 @@ module ActivePartition
13
13
  module Partitionable
14
14
  extend ActiveSupport::Concern
15
15
 
16
+ # rubocop:disable Metrics
16
17
  included do
17
18
  # when partitioned column change, create partition if needed
18
19
  # before_validation will be called with create, update, save, and create! methods
@@ -30,47 +31,50 @@ module ActivePartition
30
31
  partitioned_value = attributes[self.class.partitioned_by.to_s]
31
32
  self.class.prepare_partition(partitioned_value, self.class.partition_range)
32
33
  end
33
- end
34
-
35
- # rubocop:disable Metrics
36
- class_methods do
37
- # The range of each partition. You can change this value over time.
38
- # example: 1.month, 2.weeks, 3.hours
39
- attr_accessor :partition_range
40
- # The column name to partition the table by
41
- attr_accessor :partitioned_by
42
- # Retains partitions until the specified time [Choose one of retention_period or retention_partition_count]
43
- # For example: 1.month (1 month from now), 2.weeks (2 weeks from now), 3.hours (3 hours from now)
44
- attr_accessor :retention_period
45
- # Retains the specified number of partitions [Choose one of retention_period or retention_partition_count]
46
- attr_accessor :retention_partition_count
47
34
 
48
- def partition_adapter
49
- @@partition_adapter ||= ActivePartition::Adapters::PostgresqlAdapter.new(connection, table_name)
50
- end
35
+ class << self
36
+ def partition_adapter
37
+ @partition_adapter ||= ActivePartition::Adapters::PostgresqlAdapter.new(connection, table_name)
38
+ end
51
39
 
52
- def partition_manager
53
- @@partition_manager ||= case columns_hash[partitioned_by.to_s].type.to_s
54
- when "datetime"
55
- ActivePartition::PartitionManagers::TimeRange.new(partition_adapter, table_name)
56
- else
57
- ActivePartition::PartitionManagers::TimeRange.new(partition_adapter, table_name)
40
+ def partition_manager
41
+ @partition_manager ||= case columns_hash[partitioned_by.to_s].type.to_s
42
+ when "datetime"
43
+ ActivePartition::PartitionManagers::TimeRange.new(partition_adapter, table_name)
44
+ else
45
+ ActivePartition::PartitionManagers::TimeRange.new(partition_adapter, table_name)
46
+ end
58
47
  end
59
- end
60
48
 
61
- def delete_expired_partitions
62
- if retention_period && retention_period.is_a?(ActiveSupport::Duration)
63
- partition_manager.retain_by_time(retention_period.ago)
64
- elsif retention_partition_count
65
- partition_manager.retain_by_partition_count(retention_partition_count)
49
+ # The range of each partition. You can change this value over time.
50
+ # example: 1.month, 2.weeks, 3.hours
51
+ attr_accessor :partition_range
52
+ # The column name to partition the table by
53
+ attr_accessor :partitioned_by
54
+ # Retains partitions until the specified time [Choose one of retention_period or retention_partition_count]
55
+ # For example: 1.month (1 month from now), 2.weeks (2 weeks from now), 3.hours (3 hours from now)
56
+ attr_accessor :retention_period
57
+ # Retains the specified number of partitions [Choose one of retention_period or retention_partition_count]
58
+ attr_accessor :retention_partition_count
59
+
60
+ def delete_expired_partitions
61
+ if retention_period && retention_period.is_a?(ActiveSupport::Duration)
62
+ partition_manager.retain_by_time(retention_period.ago)
63
+ elsif retention_partition_count
64
+ partition_manager.retain_by_partition_count(retention_partition_count)
65
+ end
66
66
  end
67
- end
68
67
 
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
68
+ delegate :premake, :latest_partition_coverage_time, to: :partition_manager
69
+ delegate :retain, :retain_by_time, :retain_by_partition_count, to: :partition_manager
70
+ delegate :prepare_partition, "active_partitions_cover?", to: :partition_manager
71
+ delegate :get_all_supported_partition_tables, to: :partition_adapter
72
+ delegate :drop_partition, to: :partition_adapter
73
+ end
74
74
  end
75
+
76
+ # rubocop:disable Metrics
77
+ # class_methods do
78
+ # end
75
79
  end
76
80
  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.4.0
4
+ version: 0.5.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-24 00:00:00.000000000 Z
11
+ date: 2024-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug