1 | # frozen_string_literal: true |
||
2 | |||
3 | # Creates table for visits |
||
4 | View Code Duplication | class CreateVisits < ActiveRecord::Migration[5.1] |
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
5 | def change |
||
6 | create_table :visits, comment: 'Visits table' do |t| |
||
7 | t.references :survey, null: false, index: true |
||
8 | t.references :user, null: false, index: true |
||
9 | t.string :name, null: true |
||
10 | t.integer :number, null: false, default: 1 |
||
11 | t.datetime :visit_date, null: false, default: -> { 'CURRENT_TIMESTAMP' } |
||
12 | t.timestamps null: false, default: -> { 'CURRENT_TIMESTAMP' } |
||
13 | end |
||
14 | |||
15 | add_foreign_key :visits, :users |
||
16 | add_foreign_key :visits, :surveys |
||
17 | add_index :visits, %i[survey_id user_id number], unique: true, name: 'index_by_survey_user_number' |
||
18 | end |
||
19 | end |
||
20 |