Class: CreateSurvey

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

Class Method Summary collapse

Class Method Details

.downObject



48
49
50
51
52
53
54
55
# File 'lib/generators/templates/migration.rb', line 48

def self.down
  drop_table :survey_surveys
  drop_table :survey_questions
  drop_table :survey_options

  drop_table :survey_attempts
  drop_table :survey_answers
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/templates/migration.rb', line 2

def self.up

  # survey surveys logic
  create_table :survey_surveys do |t|
    t.string  :name
    t.text    :description
    t.integer :attempts_number, :default => 0
    t.boolean :finished, :default => false
    t.boolean :active, :default => true

    t.timestamps
  end

  create_table :survey_questions do |t|
    t.integer :survey_id
    t.string  :text

    t.timestamps
  end

  create_table :survey_options do |t|
    t.integer :question_id
    t.integer :weight, :default => 0
    t.string :text
    t.boolean :correct

    t.timestamps
  end

  # survey answer logic
  create_table :survey_attempts do |t|
    t.belongs_to :participant, :polymorphic => true
    t.integer    :survey_id
    t.boolean    :winner
    t.integer    :score
  end

  create_table :survey_answers do |t|
    t.integer    :attempt_id
    t.integer    :question_id
    t.integer    :option_id
    t.boolean    :correct
    t.timestamps
  end
end