Method: Messaging::Adapters::Postgres::Categories#create_and_partition_by_day

Defined in:
lib/messaging/adapters/postgres/categories.rb

#create_and_partition_by_day(name) ⇒ CategoryWithPartitions

Creates a table partition for the given category that in turn is partitioned based on created_at

Parameters:

  • name (String)

    the name of the category

Returns:



39
40
41
42
43
44
45
46
47
48
# File 'lib/messaging/adapters/postgres/categories.rb', line 39

def create_and_partition_by_day(name)
  table_name = Category.table_name_for(name)
  sql = <<~SQL
    CREATE TABLE IF NOT EXISTS messaging.#{table_name}
    PARTITION OF messaging.messages FOR VALUES IN ('#{name}')
    PARTITION BY RANGE (created_at);
  SQL
  connection.execute sql
  CategoryWithPartitions.new(name, table_name)
end