Class: ActsAsRelatableMigration

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

Class Method Summary collapse

Class Method Details

.downObject



20
21
22
23
24
25
26
27
# File 'lib/generators/acts_as_relatable/templates/migration.rb', line 20

def self.down
  drop_table :relationships

  remove_index :relationships, :name => "index_relationships_on_related_id"
  remove_index :relationships, :name => "poly_relationships_related"
  remove_index :relationships, :name => "index_relationships_on_relator_id"
  remove_index :relationships, :name => "poly_relationships_relator"
end

.upObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/generators/acts_as_relatable/templates/migration.rb', line 2

def self.up
  # Relationship table
  create_table :relationships do |t|
    t.integer  :relator_id
    t.string   :relator_type
    t.integer  :related_id
    t.string   :related_type
    t.timestamps
  end

  # Relationship indexes
  add_index :relationships, ["related_id"], :name => "index_relationships_on_related_id"
  add_index :relationships, ["related_type", "related_id"], :name => "poly_relationships_related"
  add_index :relationships, ["relator_id"], :name => "index_relationships_on_relator_id"
  add_index :relationships, ["relator_type", "relator_id"], :name => "poly_relationships_relator"
end