Code Duplication    Length = 14-20 lines in 2 locations

db/migrate/20180307040020_create_study_event_instruments.rb 1 location

@@ 4-17 (lines=14) @@
1
# frozen_string_literal: true
2
3
# Creates table for association class between study_events and instruments
4
class CreateStudyEventInstruments < ActiveRecord::Migration[5.1]
5
  def change
6
    create_table :study_event_instruments do |t|
7
      t.references :study_event, null: false
8
      t.references :instrument, null: false
9
      t.timestamps null: false, default: -> { 'CURRENT_TIMESTAMP' }
10
    end
11
12
    add_index :study_event_instruments, %i[study_event_id instrument_id], \
13
              unique: true, name: 'index_by_study_event_instrument' 
14
    add_foreign_key :study_event_instruments, :study_events
15
    add_foreign_key :study_event_instruments, :instruments
16
  end
17
end
18

db/migrate/20180225053906_create_items.rb 1 location

@@ 4-23 (lines=20) @@
1
# frozen_string_literal: true
2
3
# Creates table for items/questions in an instrument
4
class CreateItems < ActiveRecord::Migration[5.1]
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