Sha256: 8c3f0e7ad9eff3807b55dcd755a7a1e60c9b4fb23017de9bcbce65f378a09943

Contents?: true

Size: 636 Bytes

Versions: 10

Compression:

Stored size: 636 Bytes

Contents

class ConvertUserViewOptionsToProps < ActiveRecord::Migration
  def up
    add_column :users, :props, :jsonb, default: {}

    require "progressbar"
    users = User.all
    pbar = ProgressBar.new("users", users.count)
    users.find_each do |user|
      props = user.read_attribute(:view_options) || {}
      props["github.username"] = props.delete("github_username") if props.key?("github_username")
      props["slack.username"] = props.delete("slack_username") if props.key?("slack_username")
      user.update_column :props, props
      pbar.inc
    end
    pbar.finish
  end

  def down
    remove_column :users, :props
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
houston-core-0.9.2 db/migrate/20160625203412_convert_user_view_options_to_props.rb
houston-core-0.9.1 db/migrate/20160625203412_convert_user_view_options_to_props.rb
houston-core-0.9.0 db/migrate/20160625203412_convert_user_view_options_to_props.rb
houston-core-0.9.0.rc1 db/migrate/20160625203412_convert_user_view_options_to_props.rb
houston-core-0.8.4 db/migrate/20160625203412_convert_user_view_options_to_props.rb
houston-core-0.8.3 db/migrate/20160625203412_convert_user_view_options_to_props.rb
houston-core-0.8.2 db/migrate/20160625203412_convert_user_view_options_to_props.rb
houston-core-0.8.1 db/migrate/20160625203412_convert_user_view_options_to_props.rb
houston-core-0.8.0 db/migrate/20160625203412_convert_user_view_options_to_props.rb
houston-core-0.8.0.pre2 db/migrate/20160625203412_convert_user_view_options_to_props.rb