Class: NarratorMigration

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

Instance Method Summary collapse

Instance Method Details

#changeObject



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
# File 'lib/generators/narrator/templates/active_record/migration.rb', line 2

def change
  if table_exists?(:activities)
    say 'Activities table already exists! Narrator was unable to install.'
    raise 'Narrator was unable to resolve clashing table names.'
  else
    suppress_messages do
      create_table :activities do |t|
        t.belongs_to :owner
        t.string :owner_type
        t.belongs_to :actor
        t.string :actor_type
        t.text :context
        t.belongs_to :subject
        t.string :subject_type
        t.belongs_to :target
        t.string :target_type
        t.string :verb
        t.boolean :has_seen, default: false

        t.timestamps
      end
      add_index :activities, [:owner_id, :owner_type]
      add_index :activities, [:actor_id, :actor_type]
      add_index :activities, [:subject_id, :subject_type]
      add_index :activities, [:target_id, :target_type]
    end
    say 'Created tables for Narrator'
  end
end