Class: CreateTriviaTables

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/trivia/install/templates/db/migrate/create_trivia_tables.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
31
32
# File 'lib/generators/trivia/install/templates/db/migrate/create_trivia_tables.rb', line 2

def change
  create_table :chosen_answers, :force => true do |t|
    t.references :user
    t.references :answer
    t.references :question
    t.integer :points

    t.timestamps
  end
  add_index :chosen_answers, :user_id
  add_index :chosen_answers, :answer_id
  add_index :chosen_answers, :question_id

  create_table :answers, :force => true do |t|
    t.string :answer
    t.boolean :right, :default => false
    t.references :question

    t.timestamps
  end
  add_index :answers, :question_id

  create_table :questions, :force => true do |t|
    t.string :question, :null => false
    t.integer :points, :default => 0, :null => false
    t.datetime :published_from
    t.datetime :published_to

    t.timestamps
  end
end