Class: CreateTaggables

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

Class Method Summary collapse

Class Method Details

.downObject



22
23
24
25
# File 'lib/generators/templates/create_taggables.rb', line 22

def self.down
  drop_table :taggings
  drop_table :tags
end

.upObject



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

def self.up
  create_table :tags do |t|
    t.string :name
    t.string :kind
    t.timestamps
  end

  create_table :taggings do |t|
    t.integer :tag_id
    t.references :taggable, :polymorphic => true
    t.references :owner, :polymorphic => true
    t.timestamps
  end
  
  add_index :tags, [:name, :kind]
  add_index :taggings, [:tag_id]  
  add_index :taggings, [:taggable_id, :taggable_type]
  add_index :taggings, [:owner_id, :owner_type]
end