Code Duplication    Length = 13-19 lines in 4 locations

db/migrate/20180318125505_create_study_participants.rb 1 location

@@ 4-16 (lines=13) @@
1
# frozen_string_literal: true
2
3
# Creates tables for association class between participants and studies
4
class CreateStudyParticipants < ActiveRecord::Migration[5.1]
5
  def change
6
    create_table :study_participants do |t|
7
      t.references :participant, null: false, foreign_key: true
8
      t.references :study, null: false, foreign_key: true
9
      t.string :subject_number, null: true
10
      t.timestamps null: false, default: -> { 'CURRENT_TIMESTAMP' }
11
    end
12
13
    add_index :study_participants, %i[participant_id study_id], unique: true, name: 'index_participant_study'
14
    add_index :study_participants, %i[study_id subject_number], name: 'index_study_subject_number'
15
  end
16
end
17

db/migrate/20180217164959_create_users.rb 1 location

@@ 5-23 (lines=19) @@
2
3
# Migration to create users table
4
# Users are linked to Alexa users via Account Linking
5
class CreateUsers < ActiveRecord::Migration[5.1]
6
  def change
7
    create_table :users, comment: 'Users table' do |t|
8
      t.string :username, null: false
9
      t.string :firstname, null: true
10
      t.string :lastname, null: true
11
      t.text :access_token, null: false, default: ''
12
      t.jsonb :preferences, null: false, default: '{}'
13
      t.timestamps null: false, default: -> { 'CURRENT_TIMESTAMP' }
14
    end
15
16
    add_indexes_and_keys
17
  end
18
19
  def add_indexes_and_keys
20
    add_index :users, :preferences, using: :gin, name: 'preferences'
21
    add_index :users, :username, unique: true, name: 'username'
22
  end
23
end
24

db/migrate/20180226141928_create_visits.rb 1 location

@@ 4-19 (lines=16) @@
1
# frozen_string_literal: true
2
3
# Creates table for visits
4
class CreateVisits < ActiveRecord::Migration[5.1]
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

db/migrate/20180217164525_create_instruments.rb 1 location

@@ 4-19 (lines=16) @@
1
# frozen_string_literal: true
2
3
# Migration to create instruments table
4
class CreateInstruments < ActiveRecord::Migration[5.1]
5
  def change
6
    create_table :instruments, comment: 'Instruments table' do |t|
7
      t.string :name, null: false, unique: true, index: true
8
      t.string :version_number, null: false, default: '1.0'
9
      t.string :instrument_type, null: false, default: 'json'
10
      t.jsonb :json_content, null: false, default: '{}'
11
      t.text :csv_content, null: false, index: true, default: ''
12
      t.text :instructions, null: false, default: ''
13
      t.timestamps null: false, default: -> { 'CURRENT_TIMESTAMP' }
14
    end
15
16
    add_index :instruments, :json_content, using: :gin, name: 'instrument_json_content'
17
    add_index :instruments, %i[name version_number], unique: true
18
  end
19
end
20