diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-15 15:42:17 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-15 15:42:17 +0000 |
commit | 44fdf983bd35328dd577d3d3650d14163ef3e2b6 (patch) | |
tree | 84ff300d056cfbabb5a0fe2a9cbaa80aaeab1cc5 /db/post_migrate | |
parent | bc9fa07b26184b5c94808f704db6ea1ac81bf4de (diff) | |
download | gitlab-ce-44fdf983bd35328dd577d3d3650d14163ef3e2b6.tar.gz |
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb b/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb new file mode 100644 index 00000000000..b25b3365e12 --- /dev/null +++ b/db/post_migrate/20200325162730_schedule_backfill_push_rules_id_in_projects.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class ScheduleBackfillPushRulesIdInProjects < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + MIGRATION = 'BackfillPushRulesIdInProjects'.freeze + BATCH_SIZE = 1_000 + + class PushRules < ActiveRecord::Base + include EachBatch + + self.table_name = 'push_rules' + end + + def up + # Update one record that is connected to the instance + value_to_be_updated_to = ScheduleBackfillPushRulesIdInProjects::PushRules.find_by(is_sample: true)&.id + + execute "UPDATE application_settings SET push_rule_id = #{value_to_be_updated_to}" if value_to_be_updated_to + + ApplicationSetting.expire + + queue_background_migration_jobs_by_range_at_intervals(ScheduleBackfillPushRulesIdInProjects::PushRules, + MIGRATION, + 5.minutes, + batch_size: BATCH_SIZE) + end + + def down + execute "UPDATE application_settings SET push_rule_id = NULL" + + ApplicationSetting.expire + end +end |