You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: billboard_event_rollup.rb
    path of file: ./repos/forem/app/services
    
    the code of the file until where you have to start completion: class BillboardEventRollup
  ATTRIBUTES_PRESERVED = %i[user_id display_ad_id category context_type created_at].freeze
  ATTRIBUTES_DESTROYED = %i[id counts_for updated_at artic
    
  def compact_records(date, compacted)
    result = nil

    relation.transaction do
      result = relation.create!(compacted.to_h) do |event|
        event.created_at = date
      end

      relation.where(id: compacted.events).delete_all
    end

    result
  end