summaryrefslogtreecommitdiff
path: root/db/post_migrate/20191212162434_change_commit_user_mentions_commit_id_column_type_cleanup.rb
blob: aed9d335af98c3e24af4c1f3c3886a6775efc058 (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
# frozen_string_literal: true

class ChangeCommitUserMentionsCommitIdColumnTypeCleanup < ActiveRecord::Migration[5.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  NEW_INDEX = 'commit_id_for_type_change_and_note_id_index'
  OLD_INDEX = 'commit_user_mentions_on_commit_id_and_note_id_index'

  def up
    cleanup_concurrent_column_type_change :commit_user_mentions, :commit_id
  end

  def down
    change_column_type_concurrently :commit_user_mentions, :commit_id, :binary

    # change_column_type_concurrently creates a new index based on existing commit_id_and_note_id_index` naming it
    # `commit_id_for_type_change_and_note_id_index` so we'll rename it back to its original name.
    add_concurrent_index :commit_user_mentions, [:commit_id_for_type_change, :note_id], name: OLD_INDEX
    remove_concurrent_index_by_name :commit_user_mentions, NEW_INDEX
  end
end