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: 20151204012431_set_origin_id_into_projects_and_contributions.rb
    path of file: ./repos/catarse/db/migrate
    
    the code of the file until where you have to start completion: class SetOriginIdIntoProjectsAndContributions < ActiveRecord::Migration
  def up
    execute " set statement_timeout to 0;"
    execute <<-SQL
update projects p set origin_id = (
    select o.id
    from origins o
    where o.referral = p.referral_link
    or (o.domain = (
        select replace(ts.token, 'www.', '')
        from ts_parse('default', p.referral_link) ts
        where ts.tokid = (SELECT tokid FROM ts_token_type('default') where alias = 'host')
    ) and o.referral is null)
)
where p.referral_link is not null
and p.referral_link <> ''
    
  def up
    execute " set statement_timeout to 0;"
    execute <<-SQL
update projects p set origin_id = (
    select o.id
    from origins o
    where o.referral = p.referral_link
    or (o.domain = (
        select replace(ts.token, 'www.', '')
        from ts_parse('default', p.referral_link) ts
        where ts.tokid = (SELECT tokid FROM ts_token_type('default') where alias = 'host')
    ) and o.referral is null)
)
where p.referral_link is not null
and p.referral_link <> ''
and (
  video_thumbnail is not null
  or uploaded_image is not null);

update contributions c set origin_id = (
    select o.id
    from origins o
    where o.referral = c.referral_link
    or ( o.domain = (
        select replace(ts.token, 'www.', '')
        from ts_parse('default', c.referral_link) ts
        where ts.tokid = (SELECT tokid FROM ts_token_type('default') where alias = 'host')
    ) and o.referral is null)
)
where c.referral_link is not null
and c.referral_link <> '';
    SQL
  end