1 | # frozen_string_literal: true |
||
2 | |||
3 | # Creates table for items/questions in an instrument |
||
4 | View Code Duplication | class CreateItems < ActiveRecord::Migration[5.1] |
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
5 | def change |
||
6 | create_table :items, comment: 'Items table' do |t| |
||
7 | t.references :instrument, null: false, index: true |
||
8 | t.string :name, null: false |
||
9 | t.string :item_type, null: false |
||
10 | t.string :title, null: false |
||
11 | t.references :response_scale, null: true, index: true |
||
12 | t.boolean :is_required, null: false, default: true |
||
13 | t.timestamps null: false, default: -> { 'CURRENT_TIMESTAMP' } |
||
14 | end |
||
15 | add_keys_and_indexes |
||
16 | end |
||
17 | |||
18 | def add_keys_and_indexes |
||
19 | add_foreign_key :items, :instruments |
||
20 | add_foreign_key :items, :response_scales |
||
21 | add_index :items, :name, unique: true, name: 'index_by_item_name' |
||
22 | end |
||
23 | end |
||
24 |