Class: CreateRolesTables

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/permissify/install/templates/create_roles_tables.rb

Instance Method Summary collapse

Instance Method Details

#downObject



35
36
37
38
39
# File 'lib/generators/permissify/install/templates/create_roles_tables.rb', line 35

def down
  drop_table :roles
  drop_table :manages_roles
  drop_table :roles_users
end

#upObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/permissify/install/templates/create_roles_tables.rb', line 2

def up
  
  create_table  :roles, :force => true do |t|
    t.string    :name, :limit => 31
    t.string    :domain_type, :limit => 31
    t.text      :can_manage_roles
    t.text      :permissions
    t.timestamps
  end
  
  # the 'manages_roles' join table facilitates the expression of which roles manage other roles. 
  # see role.rb HABTM managers and manages associations.
  create_table :manages_roles, :id => false, :force => true do |t|
    t.references :manage, :null => false
    t.references :role, :null => false
  end


  # NOTE 1: when associating roles to a model/table other than 'users',
  # the 'roles_users' join table, and its :user_id field, need to be renamed.
  
  # NOTE 2: roles can be associated to multiple models/tables.
  # create a join table for each model/table which roles are associated to.
  
  create_table :roles_users, :id => false, :force => true do |t|
    t.integer :role_id, :null => false
    t.integer :user_id, :null => false
  end

  # NOTE 3: add indexes as appropriate for your app.

end