class RenameRuleMatchedToRuleIdInEvents < ActiveRecord::Migration[8.1]
  def change
    # Add new rule_id column (instant - just metadata change)
    add_column :events, :rule_id, :bigint

    # Drop old rule_matched string column (instant - no data to migrate)
    remove_column :events, :rule_matched, :string

    # Add foreign key constraint (fast - all values are NULL)
    add_foreign_key :events, :rules

    # Add index for analytics queries (fast - mostly NULL values)
    add_index :events, :rule_id
  end
end
