summaryrefslogtreecommitdiff
path: root/db/migrate/20210203092549_restore_has_external_wiki_default_value.rb
blob: 37111b370a58caff698be8f554f9bcb6b8071f46 (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
31
# frozen_string_literal: true

class RestoreHasExternalWikiDefaultValue < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  class TmpProject < ActiveRecord::Base
    self.table_name = 'projects'
  end

  # This reverts the following migration: change_column_default(:projects, :has_external_wiki, from: nil, to: false)
  # We only change the column when the current default value is false
  def up
    # Find out the current default value
    column = TmpProject.columns.find { |c| c.name == 'has_external_wiki' }
    return unless column

    if column.default == 'false'
      with_lock_retries do
        change_column_default(:projects, :has_external_wiki, from: false, to: nil)
      end
    end
  end

  def down
    # no-op
  end
end