Class: TadpollMigration

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

Class Method Summary collapse

Class Method Details

.downObject



27
28
29
30
31
# File 'lib/generators/tadpoll/migration/templates/active_record/migration.rb', line 27

def self.down
  drop_table :votes
  drop_table :polls
  drop_table :options
end

.upObject



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

def self.up
  create_table :votes do |t|
    t.references :voter, :polymorphic => true
    t.belongs_to :poll, index: true
    t.belongs_to :option, index: true

    t.timestamps
  end

  create_table :polls do |t|
    t.string :name

    t.timestamps
  end

  create_table :options do |t|
    t.string :name
    t.belongs_to :poll, index: true

    t.timestamps
  end

  add_index :votes, [:voter_id, :voter_type]
end