Updated

db/migrate / 20190420112847_add_sector_indexes_to_signatures.rb

C
35 lines of codes
3 methods
4.3 complexity/method
1 churn
12.9 complexity
45 duplications
class AddSectorIndexesToSignatures < ActiveRecord::Migration
  1. AddSectorIndexesToSignatures has no descriptive comment
disable_ddl_transaction! def up
  1. Similar code found in 4 nodes Locations: 0 1 2 3
unless index_exists?(:signatures, [:sector, :petition_id]) execute <<-SQL CREATE INDEX CONCURRENTLY index_signatures_on_sector_and_petition_id ON signatures USING btree (LEFT(postcode, -3), petition_id); SQL end unless index_exists?(:signatures, [:sector, :state, :petition_id]) execute <<-SQL CREATE INDEX CONCURRENTLY index_signatures_on_sector_and_state_and_petition_id ON signatures USING btree (LEFT(postcode, -3), state, petition_id); SQL end end def down
  1. Similar code found in 4 nodes Locations: 0 1 2 3
if index_exists?(:signatures, [:sector, :state, :petition_id]) remove_index :signatures, [:sector, :state, :petition_id] end if index_exists?(:signatures, [:sector, :petition_id]) remove_index :signatures, [:sector, :petition_id] end end private def index_exists?(table, names) select_value("SELECT to_regclass('index_#{table}_on_#{Array(names).join('_and_')}')") end end