Sha256: 38ceabc9ce266671959858e9f01c6f33af6522db4ab5b06797d98ec5c93454ec

Contents?: true

Size: 705 Bytes

Versions: 10

Compression:

Stored size: 705 Bytes

Contents

# frozen_string_literal: true

class ReplaceProfileIdWithString < ActiveRecord::Migration[4.2]
  set_role "blog_content"

  class Profile < ActiveRecord::Base
  end
  class User < ActiveRecord::Base
  end

  def up
    add_column :users, :profile, :string

    User.reset_column_information
    User.find_each do |user|
      user.update_attribute(:profile, Profile.find(user.profile_id).label)
    end

    remove_column :users, :profile_id
  end

  def down
    add_column :users, :profile_id, :integer

    User.reset_column_information
    User.find_each do |user|
      user.update_attribute(:profile_id, Profile.find_by(label: user.profile).id)
    end

    remove_column :users, :profile
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
HornsAndHooves-publify_core-10.5.0 db/migrate/20160605103918_replace_profile_id_with_string.rb
HornsAndHooves-publify_core-10.4.0 db/migrate/20160605103918_replace_profile_id_with_string.rb
HornsAndHooves-publify_core-10.3.0 db/migrate/20160605103918_replace_profile_id_with_string.rb
HornsAndHooves-publify_core-10.2.0 db/migrate/20160605103918_replace_profile_id_with_string.rb
HornsAndHooves-publify_core-10.1.1 db/migrate/20160605103918_replace_profile_id_with_string.rb
HornsAndHooves-publify_core-10.1.0 db/migrate/20160605103918_replace_profile_id_with_string.rb
HornsAndHooves-publify_core-10.0.3 db/migrate/20160605103918_replace_profile_id_with_string.rb
HornsAndHooves-publify_core-10.0.2 db/migrate/20160605103918_replace_profile_id_with_string.rb
HornsAndHooves-publify_core-10.0.1 db/migrate/20160605103918_replace_profile_id_with_string.rb
HornsAndHooves-publify_core-10.0.0 db/migrate/20160605103918_replace_profile_id_with_string.rb