style: split migration into smaller methods to reduce method length

This commit is contained in:
Shivam Mishra
2026-02-18 18:22:11 +05:30
parent 63dce7778e
commit b56765d9ba
@@ -2,6 +2,13 @@ class CreateReportingEventsRollup < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def change
create_rollups_table
add_rollups_indexes
end
private
def create_rollups_table
create_table :reporting_events_rollups do |t|
t.integer :account_id, null: false
t.date :date, null: false
@@ -14,24 +21,19 @@ class CreateReportingEventsRollup < ActiveRecord::Migration[7.1]
t.timestamps
end
end
# Unique index for upsert conflict resolution
def add_rollups_indexes
add_index :reporting_events_rollups,
[:account_id, :date, :dimension_type, :dimension_id, :metric],
unique: true,
name: 'index_rollup_unique_key',
algorithm: :concurrently
unique: true, name: 'index_rollup_unique_key', algorithm: :concurrently
# Query index for timeseries (date range scans)
add_index :reporting_events_rollups,
[:account_id, :metric, :date],
name: 'index_rollup_timeseries',
algorithm: :concurrently
name: 'index_rollup_timeseries', algorithm: :concurrently
# Query index for summaries (dimension scans)
add_index :reporting_events_rollups,
[:account_id, :dimension_type, :date],
name: 'index_rollup_summary',
algorithm: :concurrently
name: 'index_rollup_summary', algorithm: :concurrently
end
end