mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
19 lines
651 B
Ruby
19 lines
651 B
Ruby
|
|
# frozen_string_literal: true
|
||
|
|
|
||
|
|
class AddCompositeIndexToStats < ActiveRecord::Migration[8.0]
|
||
|
|
disable_ddl_transaction!
|
||
|
|
|
||
|
|
def change
|
||
|
|
# Add composite index for the most common stats lookup pattern:
|
||
|
|
# Stat.find_or_initialize_by(year:, month:, user:)
|
||
|
|
# This query is called on EVERY stats calculation
|
||
|
|
#
|
||
|
|
# Using algorithm: :concurrently to avoid locking the table during index creation
|
||
|
|
# This is crucial for production deployments with existing data
|
||
|
|
add_index :stats, %i[user_id year month],
|
||
|
|
name: 'index_stats_on_user_id_year_month',
|
||
|
|
unique: true,
|
||
|
|
algorithm: :concurrently
|
||
|
|
end
|
||
|
|
end
|