summaryrefslogtreecommitdiff
path: root/db/migrate/20220901092853_update_can_create_group_application_setting.rb
blob: 42508184d621a43f1ff4bae10d95b9b4f165ef0f (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
# frozen_string_literal: true

class UpdateCanCreateGroupApplicationSetting < Gitlab::Database::Migration[2.0]
  restrict_gitlab_migration gitlab_schema: :gitlab_main

  def up
    value = gitlab_config.respond_to?(:default_can_create_group) ? gitlab_config.default_can_create_group : true
    value = Gitlab::Utils.to_boolean(value, default: true)

    execute_update(value: value)
  end

  def down
    execute_update(value: true)
  end

  private

  def execute_update(value:)
    execute "UPDATE application_settings SET can_create_group = #{value}"
  end

  def gitlab_config
    Gitlab.config.gitlab
  end
end