summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-13 15:09:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-13 15:09:21 +0000
commitc36152ff8c41fad2f413f253eb7ac5c927e47c56 (patch)
treebbf300da207de3e8bbf272d44111ceedb18f5833 /db/post_migrate
parent286fe61013674fe2d245ffc8d2233baf09923e70 (diff)
downloadgitlab-ce-c36152ff8c41fad2f413f253eb7ac5c927e47c56.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb4
-rw-r--r--db/post_migrate/20200214173000_cleanup_empty_epic_user_mentions.rb30
-rw-r--r--db/post_migrate/20200214174519_remigrate_epic_mentions_to_db.rb38
-rw-r--r--db/post_migrate/20200214174607_remigrate_epic_notes_mentions_to_db.rb45
4 files changed, 1 insertions, 116 deletions
diff --git a/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb b/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb
index 2cbf7a69159..97f2e568a7e 100644
--- a/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb
+++ b/db/post_migrate/20191115115043_migrate_epic_mentions_to_db.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true
class MigrateEpicMentionsToDb < ActiveRecord::Migration[5.2]
- include Gitlab::Database::MigrationHelpers
-
DOWNTIME = false
disable_ddl_transaction!
@@ -28,7 +26,7 @@ class MigrateEpicMentionsToDb < ActiveRecord::Migration[5.2]
.where(QUERY_CONDITIONS)
.each_batch(of: BATCH_SIZE) do |batch, index|
range = batch.pluck(Arel.sql('MIN(epics.id)'), Arel.sql('MAX(epics.id)')).first
- migrate_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, false, *range])
+ BackgroundMigrationWorker.perform_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, false, *range])
end
end
diff --git a/db/post_migrate/20200214173000_cleanup_empty_epic_user_mentions.rb b/db/post_migrate/20200214173000_cleanup_empty_epic_user_mentions.rb
deleted file mode 100644
index ef6486675e0..00000000000
--- a/db/post_migrate/20200214173000_cleanup_empty_epic_user_mentions.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupEmptyEpicUserMentions < ActiveRecord::Migration[5.2]
- DOWNTIME = false
- BATCH_SIZE = 10000
-
- class EpicUserMention < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'epic_user_mentions'
- end
-
- def up
- return unless Gitlab.ee?
-
- # cleanup epic user mentions with no actual mentions,
- # re https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24586#note_285982468
- EpicUserMention
- .where(mentioned_users_ids: nil)
- .where(mentioned_groups_ids: nil)
- .where(mentioned_projects_ids: nil)
- .each_batch(of: BATCH_SIZE) do |batch|
- batch.delete_all
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20200214174519_remigrate_epic_mentions_to_db.rb b/db/post_migrate/20200214174519_remigrate_epic_mentions_to_db.rb
deleted file mode 100644
index 68fe031be5d..00000000000
--- a/db/post_migrate/20200214174519_remigrate_epic_mentions_to_db.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# frozen_string_literal: true
-
-class RemigrateEpicMentionsToDb < ActiveRecord::Migration[5.2]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- DELAY = 2.minutes.to_i
- BATCH_SIZE = 10000
- MIGRATION = 'UserMentions::CreateResourceUserMention'
-
- JOIN = "LEFT JOIN epic_user_mentions on epics.id = epic_user_mentions.epic_id"
- QUERY_CONDITIONS = "(description like '%@%' OR title like '%@%') AND epic_user_mentions.epic_id is null"
-
- class Epic < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'epics'
- end
-
- def up
- return unless Gitlab.ee?
-
- Epic
- .joins(JOIN)
- .where(QUERY_CONDITIONS)
- .each_batch(of: BATCH_SIZE) do |batch, index|
- range = batch.pluck(Arel.sql('MIN(epics.id)'), Arel.sql('MAX(epics.id)')).first
- migrate_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, false, *range])
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20200214174607_remigrate_epic_notes_mentions_to_db.rb b/db/post_migrate/20200214174607_remigrate_epic_notes_mentions_to_db.rb
deleted file mode 100644
index cb442233229..00000000000
--- a/db/post_migrate/20200214174607_remigrate_epic_notes_mentions_to_db.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-# frozen_string_literal: true
-
-class RemigrateEpicNotesMentionsToDb < ActiveRecord::Migration[5.2]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
-
- disable_ddl_transaction!
-
- DELAY = 2.minutes.to_i
- BATCH_SIZE = 10000
- MIGRATION = 'UserMentions::CreateResourceUserMention'
-
- INDEX_NAME = 'epic_mentions_temp_index'
- INDEX_CONDITION = "note LIKE '%@%'::text AND notes.noteable_type = 'Epic'"
- QUERY_CONDITIONS = "#{INDEX_CONDITION} AND epic_user_mentions.epic_id IS NULL"
- JOIN = 'INNER JOIN epics ON epics.id = notes.noteable_id LEFT JOIN epic_user_mentions ON notes.id = epic_user_mentions.note_id'
-
- class Note < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'notes'
- end
-
- def up
- return unless Gitlab.ee?
-
- # create temporary index for notes with mentions, may take well over 1h
- add_concurrent_index(:notes, :id, where: INDEX_CONDITION, name: INDEX_NAME)
-
- Note
- .joins(JOIN)
- .where(QUERY_CONDITIONS)
- .each_batch(of: BATCH_SIZE) do |batch, index|
- range = batch.pluck(Arel.sql('MIN(notes.id)'), Arel.sql('MAX(notes.id)')).first
- migrate_in(index * DELAY, MIGRATION, ['Epic', JOIN, QUERY_CONDITIONS, true, *range])
- end
- end
-
- def down
- # no-op
- # temporary index is to be dropped in a different migration in an upcoming release:
- # https://gitlab.com/gitlab-org/gitlab/issues/196842
- end
-end