Sha256: b5751054ebcb86ca99681a9987e403b917796c412d23a35276f0374a80a71c66

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

class UpdateRoles < ActiveRecord::Migration
  def up

    roles_users = ActiveRecord::Base.connection.select_all("select * from roles_users")
    roles_users.each do |role_user|
      secured_model = SecuredModel.find_by_secured_record_id_and_secured_record_type(role_user['user_id'], 'User')
      if secured_model.nil?
        secured_model = SecuredModel.new
        secured_model.secured_record = User.find(role_user['user_id'])
        secured_model.save
      end
      secured_model.roles << Role.find(role_user['role_id'])
    end

    roles_widgets = ActiveRecord::Base.connection.select_all("select * from roles_widgets")
    roles_widgets.each do |role_widget|
      secured_model = SecuredModel.find_by_secured_record_id_and_secured_record_type(role_widget['widget_id'], 'Widget')
      if secured_model.nil?
        secured_model = SecuredModel.new
        secured_model.secured_record = Widget.find(role_widget['widget_id'])
        secured_model.save
      end
      secured_model.roles << Role.find(role_widget['role_id'])
    end

    drop_table :roles_users
    drop_table :roles_widgets

  end

  def down
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
erp_tech_svcs-3.0.9 db/migrate/upgrade/20111109161550_update_roles.rb
erp_tech_svcs-3.0.8 db/migrate/upgrade/20111109161550_update_roles.rb
erp_tech_svcs-3.0.7 db/migrate/upgrade/20111109161550_update_roles.rb
erp_tech_svcs-3.0.6 db/migrate/upgrade/20111109161550_update_roles.rb
erp_tech_svcs-3.0.5 db/migrate/upgrade/20111109161550_update_roles.rb
erp_tech_svcs-3.0.4 db/migrate/upgrade/20111109161550_update_roles.rb
erp_tech_svcs-3.0.3 db/migrate/upgrade/20111109161550_update_roles.rb
erp_tech_svcs-3.0.2 db/migrate/upgrade/20111109161550_update_roles.rb
erp_tech_svcs-3.0.1 db/migrate/upgrade/20111109161550_update_roles.rb
erp_tech_svcs-3.0.0 db/migrate/upgrade/20111109161550_update_roles.rb