Class: RoleplayerMigration

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

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.downObject



24
25
26
# File 'lib/generators/roleplayer/migration/templates/migration.rb', line 24

def self.down
  drop_table :roles, :role_assignments
end

.upObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/roleplayer/migration/templates/migration.rb', line 3

def self.up
  
  # Role table
  create_table :roles do |t|
    t.string :name, :null => false
  end

  # Assignments table
  create_table :role_assignments do |t|
    t.references :role, :null => false
    t.references :assignee, :polymorphic => true, :null => false
  end
  
  # Create a unique index for fast lookups and for some ref. integrity
  add_index :role_assignments, 
            [ :role_id, :assignee_id, :assignee_type ],
            :unique => true, 
            :name => 'index_role_assigns_by_assignee'
  
end