20171220191323_add_index_on_namespaces_lower_name.rb 940 Bytes
Newer Older
1
class AddIndexOnNamespacesLowerName < ActiveRecord::Migration[4.2]
2 3 4 5 6 7 8 9 10
  include Gitlab::Database::MigrationHelpers
  DOWNTIME = false
  INDEX_NAME = 'index_on_namespaces_lower_name'

  disable_ddl_transaction!

  def up
    return unless Gitlab::Database.postgresql?

11
    disable_statement_timeout do
12 13 14 15 16 17
      if Gitlab::Database.version.to_f >= 9.5
        # Allow us to hot-patch the index manually ahead of the migration
        execute "CREATE INDEX CONCURRENTLY IF NOT EXISTS #{INDEX_NAME} ON namespaces (lower(name));"
      else
        execute "CREATE INDEX CONCURRENTLY #{INDEX_NAME} ON namespaces (lower(name));"
      end
18 19 20 21 22 23
    end
  end

  def down
    return unless Gitlab::Database.postgresql?

24
    disable_statement_timeout do
25 26 27 28 29
      if Gitlab::Database.version.to_f >= 9.2
        execute "DROP INDEX CONCURRENTLY IF EXISTS #{INDEX_NAME};"
      else
        execute "DROP INDEX IF EXISTS #{INDEX_NAME};"
      end
30 31 32
    end
  end
end