Class: AddEmotions

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

Instance Method Summary collapse

Instance Method Details

#downObject



21
22
23
# File 'lib/generators/emotions/templates/migration.rb', line 21

def down
  drop_table :emotions
end

#upObject



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

def up
  create_table :emotions do |t|
    # The emotional model
    t.references :emotional, polymorphic: true

    # The emotive model
    t.references :emotive, polymorphic: true

    # The type of emotion
    t.string :emotion

    t.timestamps null: false
  end

  add_index :emotions, [:emotional_type, :emotional_id, :emotive_type, :emotive_id, :emotion], unique: true, name: 'index_emotions_by_emotional_emotive_and_emotion'
  add_index :emotions, [:emotional_type, :emotional_id, :emotive_type, :emotive_id], name: 'index_emotions_by_emotional_and_emotive'
  add_index :emotions, [:emotive_type, :emotive_id, :emotion], name: 'index_emotions_by_emotive'
end