Class: PartitionGardener::DefaultPartition
- Inherits:
-
Object
- Object
- PartitionGardener::DefaultPartition
- Includes:
- Naming
- Defined in:
- lib/partition_gardener/default_partition.rb
Class Method Summary collapse
Instance Method Summary collapse
- #ensure! ⇒ Object
-
#initialize(config, executor: nil) ⇒ DefaultPartition
constructor
A new instance of DefaultPartition.
Methods included from Naming
current_partition_name, default_partition_name, future_partition_name, open_partition_name, rebalance_staging_partition_name
Constructor Details
#initialize(config, executor: nil) ⇒ DefaultPartition
Returns a new instance of DefaultPartition.
11 12 13 14 |
# File 'lib/partition_gardener/default_partition.rb', line 11 def initialize(config, executor: nil) @config = config @executor = executor || Executor.for_config(config) end |
Class Method Details
.ensure!(config, executor: nil) ⇒ Object
7 8 9 |
# File 'lib/partition_gardener/default_partition.rb', line 7 def self.ensure!(config, executor: nil) new(config, executor: executor).ensure! end |
Instance Method Details
#ensure! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/partition_gardener/default_partition.rb', line 16 def ensure! table_name = @config[:table_name] return unless Connection.table_is_partitioned?(table_name) return unless Strategy.for(@config).default_partition_required? default_name = default_partition_name(table_name) if Connection.partition_exists?(default_name) attach_existing_default!(table_name, default_name) else create_default!(table_name, default_name) end return if Connection.partition_attached?(table_name, default_name) raise MissingDefaultPartition, "Default partition #{default_name} is required for #{table_name} but is not attached" end |