diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-18 00:09:20 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-18 00:09:20 +0000 |
commit | 72721699f11187199e89631ce0b5e3d2f7c167e9 (patch) | |
tree | b51a227be89d82aa24fc954e7b50e7b0933583cc /db/post_migrate | |
parent | 06be418a7cd98a1c87c41ba43cca1ce9acbe885e (diff) | |
download | gitlab-ce-72721699f11187199e89631ce0b5e3d2f7c167e9.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20200207184023_add_temporary_index_to_promotion_notes.rb | 23 | ||||
-rw-r--r-- | db/post_migrate/20200207185149_schedule_fix_orphan_promoted_issues.rb | 35 |
2 files changed, 58 insertions, 0 deletions
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 |