Files
ubicloud/migrate/20241213_archived_record.rb
Benjamin Satzger 7ba508f55a Migration: Add partitioned table archived_record
This commit introduces the archived_record table, similar in schema to
deleted_record but without an id column or a uniqueness constraint. The
table is range-partitioned by the archived_at column and includes an
index on (model_name, archived_at). This allows for efficient execution
of queries that filter on both model_name and archived_at.

Monthly partitions are pre-created until Jan 2026. A follow-up commit
adds a test that starts failing when it's getting time to create new
partitions.
2024-12-14 11:48:31 +01:00

21 lines
682 B
Ruby

# frozen_string_literal: true
Sequel.migration do
change do
create_table(:archived_record, partition_by: :archived_at, partition_type: :range) do
column :archived_at, :timestamptz, null: false, default: Sequel::CURRENT_TIMESTAMP
column :model_name, :text, null: false
column :model_values, :jsonb, null: false, default: "{}"
index [:model_name, :archived_at]
end
first_month = Date.new(2024, 12, 1)
Array.new(14) { |i| first_month.next_month(i) }.each do |month|
create_table("archived_record_#{month.strftime("%Y_%m")}", partition_of: :archived_record) do
from month
to month.next_month
end
end
end
end