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 | |
parent | 06be418a7cd98a1c87c41ba43cca1ce9acbe885e (diff) | |
download | gitlab-ce-72721699f11187199e89631ce0b5e3d2f7c167e9.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-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 | ||||
-rw-r--r-- | db/schema.rb | 1 |
3 files changed, 59 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 diff --git a/db/schema.rb b/db/schema.rb index 0259c63d3e5..435d994e201 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2811,6 +2811,7 @@ ActiveRecord::Schema.define(version: 2020_02_13_220211) do t.index ["id"], name: "epic_mentions_temp_index", where: "((note ~~ '%@%'::text) AND ((noteable_type)::text = 'Epic'::text))" t.index ["line_code"], name: "index_notes_on_line_code" t.index ["note"], name: "index_notes_on_note_trigram", opclass: :gin_trgm_ops, using: :gin + t.index ["note"], name: "tmp_idx_on_promoted_notes", where: "(((noteable_type)::text = 'Issue'::text) AND (system IS TRUE) AND (note ~~ 'promoted to epic%'::text))" t.index ["noteable_id", "noteable_type"], name: "index_notes_on_noteable_id_and_noteable_type" t.index ["project_id", "id"], name: "index_notes_on_project_id_and_id_and_system_false", where: "(NOT system)" t.index ["project_id", "noteable_type"], name: "index_notes_on_project_id_and_noteable_type" |