Class: Tablature::Adapters::Postgres::Handlers::Range Private
- Defined in:
- lib/tablature/adapters/postgres/handlers/range.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #create_range_partition(table_name, options, &block) ⇒ Object private
- #create_range_partition_of(parent_table, options) ⇒ Object private
-
#initialize(connection) ⇒ Range
constructor
private
A new instance of Range.
Methods included from UUID
Methods included from Quoting
#quote_collection, #quote_partition_key
Constructor Details
#initialize(connection) ⇒ Range
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Range.
9 10 11 |
# File 'lib/tablature/adapters/postgres/handlers/range.rb', line 9 def initialize(connection) @connection = connection end |
Instance Method Details
#create_range_partition(table_name, options, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tablature/adapters/postgres/handlers/range.rb', line 13 def create_range_partition(table_name, , &block) raise_unless_range_partition_supported # Postgres 10 does not handle indexes and therefore primary keys. # Therefore we manually create an `id` column. # TODO: Either make the library Postgres 11 only, or two code paths between Postgres 10 # and Postgres 11. = .except(:id, :primary_key, :partition_key) = extract_primary_key!(.slice(:id, :primary_key)) partition_key = .fetch(:partition_key) [:id] = false [:options] = "PARTITION BY RANGE (#{quote_partition_key(partition_key)})" create_partition(table_name, , , &block) end |
#create_range_partition_of(parent_table, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tablature/adapters/postgres/handlers/range.rb', line 31 def create_range_partition_of(parent_table, ) range_start = .fetch(:range_start, nil) range_end = .fetch(:range_end, nil) raise MissingRangePartitionBoundsError if range_start.nil? || range_end.nil? name = .fetch(:name, partition_name(parent_table, range_start, range_end)) # TODO: Call `create_table` here instead of running the query. # TODO: Pass the options to `create_table` to allow further configuration of the table, # e.g. sub-partitioning the table. query = " CREATE TABLE \#{quote_table_name(name)} PARTITION OF \#{quote_table_name(parent_table)}\n FOR VALUES FROM (\#{quote(range_start)}) TO (\#{quote(range_end)});\n SQL\n\n execute(query)\nend\n".strip |