Class: ActsPermissiveMigration

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

Class Method Summary collapse

Class Method Details

.downObject



53
54
55
56
57
58
# File 'lib/generators/templates/permissive_migration.rb', line 53

def self.down
  drop_table :permissive_circles
  drop_table :permissive_permissions
  drop_table :permissive_circlings
  drop_table :permissive_groupings
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/templates/permissive_migration.rb', line 2

def self.up

  # This table holds a mask of permissions and links to a specific circle
  create_table :permissive_permissions do |t|
    t.integer :circle_id
    t.integer :mask, :null => false, :default => 0

    t.timestamps
  end

  # This table polymorphically joins arbitrary acts_permissive objects to
  # the permissions table
  create_table :permissive_groupings do |t|
    t.integer :permission_id
    t.integer :permissible_id
    t.string  :permissible_type

    t.timestamps
  end

  # This defines the actual names of the circles ("yada", "super-awesome-people", "banana")
  create_table :permissive_circles do |t|
    t.string  :name
    t.string  :guid

    t.timestamps
  end

  # This table polymorphically joins arbitrary is_used_permissively objects
  # to the circles table
  create_table :permissive_circlings do |t|
    t.string    :circleable_type
    t.integer   :circleable_id
    t.integer   :circle_id

    t.timestamps
  end

  add_index :permissive_permissions, :circle_id, :name => "circles_index"
  add_index :permissive_permissions, :mask, :name => "masks_masks"

  add_index :permissive_groupings, [:permissible_id, :permissible_type], :name => "grouper_index"
  add_index :permissive_groupings, :permission_id, :name => "permission_grouping_index"

  add_index :permissive_circles, :guid, :name => "circle_guids_index"
  add_index :permissive_circles, :name, :name => "circle_name_index"

  add_index :permissive_circlings, [:circleable_id, :circleable_type], :name => "thing_circling_index"
  add_index :permissive_circlings, :circle_id, :name => "circle_circling_index"
end