Class: CreateStrongboltTables

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/strongbolt/templates/migration.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/generators/strongbolt/templates/migration.rb', line 2

def change
  create_table :strongbolt_capabilities, force: true do |t|
    t.string   :name
    t.string   :description
    t.string   :model
    t.string   :action
    t.string   :attr
    t.boolean  :require_ownership, default: false, null: false
    t.boolean  :require_tenant_access, default: true, null: false

    t.timestamps
  end

  create_table :strongbolt_roles, force: true do |t|
    t.string   :name
    t.integer  :parent_id
    t.integer  :lft
    t.integer  :rgt
    t.string   :description

    t.timestamps
  end

  create_table :strongbolt_user_groups, force: true do |t|
    t.string :name
    t.text :description

    t.timestamps
  end

  create_table :strongbolt_user_groups_users, force: true do |t|
    t.integer :user_group_id
    t.integer :user_id
  end

  create_table :strongbolt_roles_user_groups, force: true do |t|
    t.integer :user_group_id
    t.integer :role_id
  end

  create_table :strongbolt_capabilities_roles, force: true do |t|
    t.integer  :role_id
    t.integer  :capability_id
  end

  create_table :strongbolt_users_tenants, force: true do |t|
    t.integer  :user_id
    t.integer  :tenant_id
    t.string   :type
  end

  # Indexes
  add_index :strongbolt_roles, :parent_id
  add_index :strongbolt_roles, :lft
  add_index :strongbolt_roles, :rgt

  add_index :strongbolt_user_groups_users, :user_group_id
  add_index :strongbolt_user_groups_users, :user_id

  add_index :strongbolt_roles_user_groups, :user_group_id
  add_index :strongbolt_roles_user_groups, :role_id

  add_index :strongbolt_capabilities_roles, :role_id
  add_index :strongbolt_capabilities_roles, :capability_id

  add_index :strongbolt_users_tenants, :user_id
  add_index :strongbolt_users_tenants, :tenant_id
  add_index :strongbolt_users_tenants, :type
  add_index :strongbolt_users_tenants, i[tenant_id type]

  add_index :strongbolt_user_groups_users, i[user_group_id user_id], unique: true, name: :index_strongbolt_user_groups_users_unique
end