summaryrefslogtreecommitdiff
path: root/db/migrate/20171220191323_add_index_on_namespaces_lower_name.rb
blob: 7cf1d0cec68f79a7936f30ffedd452140fd5f161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class AddIndexOnNamespacesLowerName < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers
  DOWNTIME = false
  INDEX_NAME = 'index_on_namespaces_lower_name'

  disable_ddl_transaction!

  def up
    return unless Gitlab::Database.postgresql?

    disable_statement_timeout
    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
  end

  def down
    return unless Gitlab::Database.postgresql?

    disable_statement_timeout
    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
  end
end