Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20230723203612_backfill_default_branch_protection_application_setting.rb')
-rw-r--r--db/migrate/20230723203612_backfill_default_branch_protection_application_setting.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/db/migrate/20230723203612_backfill_default_branch_protection_application_setting.rb b/db/migrate/20230723203612_backfill_default_branch_protection_application_setting.rb
new file mode 100644
index 00000000000..6c6231117e1
--- /dev/null
+++ b/db/migrate/20230723203612_backfill_default_branch_protection_application_setting.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+class BackfillDefaultBranchProtectionApplicationSetting < Gitlab::Database::Migration[2.1]
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+
+ class ApplicationSetting < MigrationRecord
+ self.table_name = 'application_settings'
+ end
+
+ BRANCH_PROTECTION = [
+ { "allow_force_push" => true,
+ "allowed_to_merge" => [{ "access_level" => 30 }],
+ "allowed_to_push" => [{ "access_level" => 30 }] },
+ { "allow_force_push" => false,
+ "allowed_to_merge" => [{ "access_level" => 30 }],
+ "allowed_to_push" => [{ "access_level" => 30 }] },
+ { "allow_force_push" => false,
+ "allowed_to_merge" => [{ "access_level" => 40 }],
+ "allowed_to_push" => [{ "access_level" => 40 }] },
+ { "allow_force_push" => true,
+ "allowed_to_merge" => [{ "access_level" => 30 }],
+ "allowed_to_push" => [{ "access_level" => 40 }] },
+ { "allow_force_push" => true,
+ "allowed_to_merge" => [{ "access_level" => 30 }],
+ "allowed_to_push" => [{ "access_level" => 40 }],
+ "developer_can_initial_push" => true }
+ ]
+
+ def up
+ ApplicationSetting.reset_column_information
+
+ ApplicationSetting.find_each do |application_setting|
+ level = application_setting.default_branch_protection.to_i
+ protection_hash = BRANCH_PROTECTION[level]
+ application_setting.update!(default_branch_protection_defaults: protection_hash)
+ end
+ end
+
+ def down
+ ApplicationSetting.reset_column_information
+
+ ApplicationSetting.update_all(default_branch_protection_defaults: {})
+ end
+end