CreateVisits   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 16
loc 16
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
This code seems to be duplicated in your project.
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