Class: Code0::ZeroTrack::Database::Partitioning::Strategy::Base
- Inherits:
-
Object
- Object
- Code0::ZeroTrack::Database::Partitioning::Strategy::Base
- Defined in:
- lib/code0/zero_track/database/partitioning/strategy/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#headroom ⇒ Object
readonly
Returns the value of attribute headroom.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#partitioning_column ⇒ Object
readonly
Returns the value of attribute partitioning_column.
-
#retain_detached_for ⇒ Object
readonly
Returns the value of attribute retain_detached_for.
-
#retain_for ⇒ Object
readonly
Returns the value of attribute retain_for.
Instance Method Summary collapse
- #current_partitions ⇒ Object
- #default_headroom ⇒ Object
- #desired_partitions ⇒ Object
-
#initialize(model, partitioning_column, headroom: default_headroom, retain_for: nil, retain_detached_for: 7.days) ⇒ Base
constructor
A new instance of Base.
- #oldest_active_date ⇒ Object
- #partition_name(lower_bound) ⇒ Object
- #partitions_to_create ⇒ Object
- #partitions_to_detach ⇒ Object
- #partitions_to_drop ⇒ Object
- #retention_enabled? ⇒ Boolean
Constructor Details
#initialize(model, partitioning_column, headroom: default_headroom, retain_for: nil, retain_detached_for: 7.days) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 11 def initialize( model, partitioning_column, headroom: default_headroom, retain_for: nil, retain_detached_for: 7.days ) @model = model @partitioning_column = partitioning_column @headroom = headroom @retain_for = retain_for @retain_detached_for = retain_detached_for end |
Instance Attribute Details
#headroom ⇒ Object (readonly)
Returns the value of attribute headroom.
9 10 11 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 9 def headroom @headroom end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
9 10 11 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 9 def model @model end |
#partitioning_column ⇒ Object (readonly)
Returns the value of attribute partitioning_column.
9 10 11 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 9 def partitioning_column @partitioning_column end |
#retain_detached_for ⇒ Object (readonly)
Returns the value of attribute retain_detached_for.
9 10 11 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 9 def retain_detached_for @retain_detached_for end |
#retain_for ⇒ Object (readonly)
Returns the value of attribute retain_for.
9 10 11 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 9 def retain_for @retain_for end |
Instance Method Details
#current_partitions ⇒ Object
25 26 27 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 25 def current_partitions raise NotImplementedError end |
#default_headroom ⇒ Object
41 42 43 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 41 def default_headroom raise NotImplementedError end |
#desired_partitions ⇒ Object
29 30 31 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 29 def desired_partitions raise NotImplementedError end |
#oldest_active_date ⇒ Object
33 34 35 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 33 def oldest_active_date raise NotImplementedError end |
#partition_name(lower_bound) ⇒ Object
37 38 39 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 37 def partition_name(lower_bound) raise NotImplementedError end |
#partitions_to_create ⇒ Object
45 46 47 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 45 def partitions_to_create desired_partitions - current_partitions end |
#partitions_to_detach ⇒ Object
49 50 51 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 49 def partitions_to_detach current_partitions - desired_partitions end |
#partitions_to_drop ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 53 def partitions_to_drop partitioned_table = PostgresPartitionedTable.find_by(identifier: model.table_name) if partitioned_table.nil? logger.warn(message: 'Failed to find partitioned table', identifier: model.table_name) return [] end partitioned_table.postgres_detached_partitions.detached_before(retain_detached_for.ago) end |
#retention_enabled? ⇒ Boolean
64 65 66 |
# File 'lib/code0/zero_track/database/partitioning/strategy/base.rb', line 64 def retention_enabled? retain_for.present? end |