Updated

db/migrate / 20170909095357_add_sponsor_partial_index_to_signatures.rb

C
27 lines of codes
3 methods
4.0 complexity/method
1 churn
12.02 complexity
40 duplications
class AddSponsorPartialIndexToSignatures < ActiveRecord::Migration
  1. AddSponsorPartialIndexToSignatures has no descriptive comment
disable_ddl_transaction! def up unless index_exists?(:signatures, name: "index_signatures_on_petition_id_where_sponsor_is_true")
  1. Similar code found in 2 nodes Locations: 0 1
add_index :signatures, :petition_id, where: "sponsor = 't'", algorithm: :concurrently, name: "index_signatures_on_petition_id_where_sponsor_is_true" end end def down if index_exists?(:signatures, name: "index_signatures_on_petition_id_where_sponsor_is_true") remove_index :signatures, name: "index_signatures_on_petition_id_where_sponsor_is_true" end end private def index_exists?(table, names_or_options)
  1. Identical code found in 2 nodes Locations: 0 1
if names_or_options.is_a?(Hash) select_value("SELECT to_regclass('#{names_or_options[:name]}')") else select_value("SELECT to_regclass('index_#{table}_on_#{Array(names_or_options).join('_and_')}')") end end end