From 72721699f11187199e89631ce0b5e3d2f7c167e9 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 18 Feb 2020 00:09:20 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- ...84023_add_temporary_index_to_promotion_notes.rb | 23 ++++++++++++++ ...07185149_schedule_fix_orphan_promoted_issues.rb | 35 ++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 db/post_migrate/20200207184023_add_temporary_index_to_promotion_notes.rb create mode 100644 db/post_migrate/20200207185149_schedule_fix_orphan_promoted_issues.rb (limited to 'db/post_migrate') diff --git a/db/post_migrate/20200207184023_add_temporary_index_to_promotion_notes.rb b/db/post_migrate/20200207184023_add_temporary_index_to_promotion_notes.rb new file mode 100644 index 00000000000..44a32938483 --- /dev/null +++ b/db/post_migrate/20200207184023_add_temporary_index_to_promotion_notes.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddTemporaryIndexToPromotionNotes < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :notes, + :note, + where: "noteable_type = 'Issue' AND system IS TRUE AND note LIKE 'promoted to epic%'", + name: 'tmp_idx_on_promoted_notes' + end + + def down + # NO OP + end +end diff --git a/db/post_migrate/20200207185149_schedule_fix_orphan_promoted_issues.rb b/db/post_migrate/20200207185149_schedule_fix_orphan_promoted_issues.rb new file mode 100644 index 00000000000..83ba56501dd --- /dev/null +++ b/db/post_migrate/20200207185149_schedule_fix_orphan_promoted_issues.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +class ScheduleFixOrphanPromotedIssues < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 100 + BACKGROUND_MIGRATION = 'FixOrphanPromotedIssues'.freeze + + disable_ddl_transaction! + + class Note < ActiveRecord::Base + include EachBatch + + self.table_name = 'notes' + + scope :of_promotion, -> do + where(noteable_type: 'Issue') + .where('notes.system IS TRUE') + .where("notes.note LIKE 'promoted to epic%'") + end + end + + def up + Note.of_promotion.each_batch(of: BATCH_SIZE) do |notes, index| + jobs = notes.map { |note| [BACKGROUND_MIGRATION, [note.id]] } + + BackgroundMigrationWorker.bulk_perform_async(jobs) + end + end + + def down + # NO OP + end +end -- cgit v1.2.1