Class: Tablature::Adapters::Postgres::Handlers::List Private

Inherits:
Base
  • Object
show all
Defined in:
lib/tablature/adapters/postgres/handlers/list.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

Methods included from UUID

#uuid_function

Methods included from Quoting

#quote_collection, #quote_partition_key

Constructor Details

#initialize(connection) ⇒ List

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 List.



9
10
11
# File 'lib/tablature/adapters/postgres/handlers/list.rb', line 9

def initialize(connection)
  @connection = connection
end

Instance Method Details

#create_list_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
# File 'lib/tablature/adapters/postgres/handlers/list.rb', line 13

def create_list_partition(table_name, options, &block)
  raise_unless_list_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.
  modified_options = options.except(:id, :primary_key, :partition_key)
  id_options = extract_primary_key!(options.slice(:id, :primary_key))
  partition_key = options.fetch(:partition_key)

  modified_options[:id]      = false
  modified_options[:options] = "PARTITION BY LIST (#{quote_partition_key(partition_key)})"

  create_partition(table_name, id_options, modified_options, &block)
end

#create_list_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.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tablature/adapters/postgres/handlers/list.rb', line 30

def create_list_partition_of(parent_table, options)
  values = options.fetch(:values, [])
  raise MissingListPartitionValuesError if values.blank?

  name = options.fetch(:name, partition_name(parent_table, values))
  # 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 = <<~SQL.strip
    CREATE TABLE #{quote_table_name(name)} PARTITION OF #{quote_table_name(parent_table)}
    FOR VALUES IN (#{quote_collection(values)})
  SQL

  execute(query)
end