cirandas.net

ref: master

db/migrate/082_add_invite_members_permission_to_admins.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class AddInviteMembersPermissionToAdmins < ActiveRecord::Migration
  def self.up
    select_all("SELECT * from roles where key = 'profile_admin'").each do |role|
      permissions = (YAML.load(role['permissions']) + ['invite_members']).to_yaml
      role_id = role['id']
      update("update roles set permissions = '%s' where id = %d" % [permissions, role_id])
    end
  end

  def self.down
    select_all("SELECT * from roles where key = 'profile_admin'").each do |role|
      permissions = (YAML.load(role['permissions']) - ['invite_members']).to_yaml
      role_id = role['id']
      update("update roles set permissions = '%s' where id = %d" % [permissions, role_id])
    end
  end
end