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: 20140701123203_add_events_per_week_to_conference.rb
    path of file: ./repos/osem/db/migrate
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

class AddEventsPerWeekToConference < ActiveRecord::Migration
  class TempVersion < ActiveRecord::Base
    self.table_name = 'versions'
    serialize :object_changes, HashWithIndifferentAccess
  end

  class TempEvent < ActiveRecord::Base
    self.table_name = 'events'
  end

  class TempConference < ActiveRecord::Base
    self.table_name = 'conferences'
    serialize :events_per_week, Hash
  end

  def up
    add_column :conferences, :events_per_week, :text
    TempConference.reset_column_information

    TempVersion.where(item_
    
  def up
    add_column :conferences, :events_per_week, :text
    TempConference.reset_column_information

    TempVersion.where(item_type: 'Event').each do |event_version|
      event = TempEvent.find_by_id(event_version.item_id)
      if event
        conference = TempConference.find_by_id(event.conference_id)
        if conference
          week = event_version.created_at.end_of_week

          no_events = {
              new:         0,
              withdrawn:   0,
              unconfirmed: 0,
              confirmed:   0,
              canceled:    0,
              rejected:    0,
          }

          if !conference.events_per_week
            conference.events_per_week = {
                week => no_events
            }
          elsif !conference.events_per_week[week]
            conference.events_per_week[week] = no_events
          end

          if event_version.object_changes &&
              event_version.event == 'create'

            # Increment the new state
            conference.events_per_week[week][:new] += 1
          elsif event_version.object_changes &&
              event_version.object_changes[:state]

            prev_state = event_version.object_changes[:state][0].to_sym
            next_state = event_version.object_changes[:state][1].to_sym

            # Backward compatibility: deprecated state :review now :new
            if prev_state == :review
              prev_state = :new
            elsif  next_state == :review
              next_state = :new
            end