summaryrefslogtreecommitdiff
path: root/db/post_migrate
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20200127111953_cleanup_empty_snippet_user_mentions.rb28
-rw-r--r--db/post_migrate/20200127131953_migrate_snippet_mentions_to_db.rb35
-rw-r--r--db/post_migrate/20200127141953_add_temporary_snippet_notes_with_mentions_index.rb20
-rw-r--r--db/post_migrate/20200127151953_migrate_snippet_notes_mentions_to_db.rb38
4 files changed, 0 insertions, 121 deletions
diff --git a/db/post_migrate/20200127111953_cleanup_empty_snippet_user_mentions.rb b/db/post_migrate/20200127111953_cleanup_empty_snippet_user_mentions.rb
deleted file mode 100644
index aad688fef3f..00000000000
--- a/db/post_migrate/20200127111953_cleanup_empty_snippet_user_mentions.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-class CleanupEmptySnippetUserMentions < ActiveRecord::Migration[5.2]
- DOWNTIME = false
- BATCH_SIZE = 10_000
-
- class SnippetUserMention < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'snippet_user_mentions'
- end
-
- def up
- # cleanup snippet user mentions with no actual mentions,
- # re https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24586#note_285982468
- SnippetUserMention
- .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/20200127131953_migrate_snippet_mentions_to_db.rb b/db/post_migrate/20200127131953_migrate_snippet_mentions_to_db.rb
deleted file mode 100644
index e25c2c2982a..00000000000
--- a/db/post_migrate/20200127131953_migrate_snippet_mentions_to_db.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-# frozen_string_literal: true
-
-class MigrateSnippetMentionsToDb < ActiveRecord::Migration[5.2]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- DELAY = 2.minutes.to_i
- BATCH_SIZE = 10_000
- MIGRATION = 'UserMentions::CreateResourceUserMention'
-
- JOIN = "LEFT JOIN snippet_user_mentions on snippets.id = snippet_user_mentions.snippet_id"
- QUERY_CONDITIONS = "(description like '%@%' OR title like '%@%') AND snippet_user_mentions.snippet_id IS NULL"
-
- disable_ddl_transaction!
-
- class Snippet < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'snippets'
- end
-
- def up
- Snippet
- .joins(JOIN)
- .where(QUERY_CONDITIONS)
- .each_batch(of: BATCH_SIZE) do |batch, index|
- range = batch.pluck(Arel.sql('MIN(snippets.id)'), Arel.sql('MAX(snippets.id)')).first
- migrate_in(index * DELAY, MIGRATION, ['Snippet', JOIN, QUERY_CONDITIONS, false, *range])
- end
- end
-
- def down
- # no-op
- end
-end
diff --git a/db/post_migrate/20200127141953_add_temporary_snippet_notes_with_mentions_index.rb b/db/post_migrate/20200127141953_add_temporary_snippet_notes_with_mentions_index.rb
deleted file mode 100644
index ec9b8b76f6f..00000000000
--- a/db/post_migrate/20200127141953_add_temporary_snippet_notes_with_mentions_index.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class AddTemporarySnippetNotesWithMentionsIndex < ActiveRecord::Migration[5.2]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- INDEX_NAME = 'snippet_mentions_temp_index'
- INDEX_CONDITION = "note LIKE '%@%'::text AND notes.noteable_type = 'Snippet'"
-
- disable_ddl_transaction!
-
- def up
- # create temporary index for notes with mentions, may take well over 1h
- add_concurrent_index(:notes, :id, where: INDEX_CONDITION, name: INDEX_NAME)
- end
-
- def down
- remove_concurrent_index(:notes, :id, where: INDEX_CONDITION, name: INDEX_NAME)
- end
-end
diff --git a/db/post_migrate/20200127151953_migrate_snippet_notes_mentions_to_db.rb b/db/post_migrate/20200127151953_migrate_snippet_notes_mentions_to_db.rb
deleted file mode 100644
index 3795a96b426..00000000000
--- a/db/post_migrate/20200127151953_migrate_snippet_notes_mentions_to_db.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# frozen_string_literal: true
-
-class MigrateSnippetNotesMentionsToDb < ActiveRecord::Migration[5.2]
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- DELAY = 2.minutes.to_i
- BATCH_SIZE = 10_000
- MIGRATION = 'UserMentions::CreateResourceUserMention'
-
- INDEX_CONDITION = "note LIKE '%@%'::text AND notes.noteable_type = 'Snippet'"
- QUERY_CONDITIONS = "#{INDEX_CONDITION} AND snippet_user_mentions.snippet_id IS NULL"
- JOIN = 'INNER JOIN snippets ON snippets.id = notes.noteable_id LEFT JOIN snippet_user_mentions ON notes.id = snippet_user_mentions.note_id'
-
- disable_ddl_transaction!
-
- class Note < ActiveRecord::Base
- include EachBatch
-
- self.table_name = 'notes'
- end
-
- def up
- 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, ['Snippet', 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