20200620164023_add_fixed_lowercase_index_to_accounts.rb 959 B

123456789101112131415
  1. class AddFixedLowercaseIndexToAccounts < ActiveRecord::Migration[5.2]
  2. disable_ddl_transaction!
  3. def up
  4. rename_index :accounts, 'index_accounts_on_username_and_domain_lower', 'old_index_accounts_on_username_and_domain_lower' unless index_name_exists?(:accounts, 'old_index_accounts_on_username_and_domain_lower')
  5. add_index :accounts, "lower (username), COALESCE(lower(domain), '')", name: 'index_accounts_on_username_and_domain_lower', unique: true, algorithm: :concurrently
  6. remove_index :accounts, name: 'old_index_accounts_on_username_and_domain_lower'
  7. end
  8. def down
  9. add_index :accounts, 'lower (username), lower(domain)', name: 'old_index_accounts_on_username_and_domain_lower', unique: true, algorithm: :concurrently
  10. remove_index :accounts, name: 'index_accounts_on_username_and_domain_lower'
  11. rename_index :accounts, 'old_index_accounts_on_username_and_domain_lower', 'index_accounts_on_username_and_domain_lower'
  12. end
  13. end