Updated

db/migrate / 20160819062044_add_domain_index_to_signatures.rb

A
24 lines of codes
3 methods
2.8 complexity/method
1 churn
8.25 complexity
0 duplications
class AddDomainIndexToSignatures < ActiveRecord::Migration
  1. AddDomainIndexToSignatures has no descriptive comment
disable_ddl_transaction! def up unless index_exists?(:signatures, :domain) execute <<-SQL CREATE INDEX CONCURRENTLY index_signatures_on_domain ON signatures USING btree (SUBSTRING(email FROM POSITION('@' IN email) + 1)); SQL end end def down if index_exists?(:signatures, :domain) remove_index :signatures, :domain end end private def index_exists?(table, names) select_value("SELECT to_regclass('index_#{table}_on_#{Array(names).join('_and_')}')") end end