Sha256: e211dca49e3974ebdeea6517910e368c02c2b903c5a1800cbb94a7290dd16899

Contents?: true

Size: 518 Bytes

Versions: 30

Compression:

Stored size: 518 Bytes

Contents

class AddCommentUserId < ActiveRecord::Migration
  class BareComment < ActiveRecord::Base
    include BareMigration
  end

  class BareUser <  ActiveRecord::Base
    include BareMigration
  end

  def self.up
    id_for_address = BareUser.find(:all).inject({}) do |h, u|
      h.merge({ u.email => u.id })
    end

    modify_tables_and_update(:add_column, BareComment, :user_id, :integer) do |c|
      c.user_id = id_for_address[c.email]
    end
  end

  def self.down
    remove_column :comments, :user_id
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
typo-5.0.3.98 db/migrate/017_add_comment_user_id.rb
typo-5.0 db/migrate/017_add_comment_user_id.rb
typo-5.1.1 db/migrate/017_add_comment_user_id.rb
typo-5.1.2 db/migrate/017_add_comment_user_id.rb
typo-5.1.3 db/migrate/017_add_comment_user_id.rb
typo-5.1 db/migrate/017_add_comment_user_id.rb
typo-5.1.98 db/migrate/017_add_comment_user_id.rb
typo-5.2 db/migrate/017_add_comment_user_id.rb
typo-5.2.98 db/migrate/017_add_comment_user_id.rb
typo-5.3 db/migrate/017_add_comment_user_id.rb