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: 20190717151612_add_temporality_to_catalog_items.rb
    path of file: ./repos/ekylibre/db/migrate
    
    the code of the file until where you have to start completion: class AddTemporalityToCatalogItems < ActiveRecord::Migration[4.2]
  def up
    add_column    :catalog_items, :started_at, :datetime
    add_column    :catalog_items, :stopped_at, :datetime
    add_column    :catalog_items, :reference_name, :string
    add_reference :catalog_items, :unit, index: true

    execute <<-SQL
      UPDATE catalog_items AS ci
 
    
  def up
    add_column    :catalog_items, :started_at, :datetime
    add_column    :catalog_items, :stopped_at, :datetime
    add_column    :catalog_items, :reference_name, :string
    add_reference :catalog_items, :unit, index: true

    execute <<-SQL
      UPDATE catalog_items AS ci
        SET started_at = ci.created_at,
            unit_id = u.id
      FROM product_nature_variants AS v
        INNER JOIN units AS u
          ON v.default_unit_id = u.base_unit_id
            AND v.default_quantity = u.coefficient
      WHERE ci.variant_id = v.id;

      UPDATE catalog_items AS ci
        SET started_at = ci.created_at,
            unit_id = u.id
      FROM product_nature_variants AS v
        INNER JOIN units AS u
          ON u.reference_name = v.default_unit_name
      WHERE ci.variant_id = v.id
        AND ci.unit_id IS NULL
    SQL

    change_column_null :catalog_items, :started_at, false
    change_column_null :catalog_items, :unit_id, false
    remove_index       :catalog_items, name: :index_catalog_items_on_catalog_id_and_variant_id
  end