summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-04-06 03:23:05 +0000
committerStan Hu <stanhu@gmail.com>2019-04-06 03:23:05 +0000
commit7a7c131f7bb69e398a6e2079c11c55bddd8e2bc8 (patch)
tree034e53b3f1f420aa9b7ac777b1eb458c3d4054c7 /db
parent3198867fe3d6257aff61d6a4c0e3768f35bcc6b5 (diff)
parenta8a4518099cceec5826bb9ea5d9e3198c5a10698 (diff)
downloadgitlab-ce-7a7c131f7bb69e398a6e2079c11c55bddd8e2bc8.tar.gz
Merge branch '58612-clean-up-notes-data' into 'master'
Clean up `noteable_id` for notes on commits Closes #58612 See merge request gitlab-org/gitlab-ce!26104
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20190313092516_clean_up_noteable_id_for_notes_on_commits.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/db/post_migrate/20190313092516_clean_up_noteable_id_for_notes_on_commits.rb b/db/post_migrate/20190313092516_clean_up_noteable_id_for_notes_on_commits.rb
new file mode 100644
index 00000000000..fcd63f42b0e
--- /dev/null
+++ b/db/post_migrate/20190313092516_clean_up_noteable_id_for_notes_on_commits.rb
@@ -0,0 +1,33 @@
+# 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 CleanUpNoteableIdForNotesOnCommits < ActiveRecord::Migration[5.0]
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ TEMP_INDEX_NAME = 'index_notes_on_commit_with_null_noteable_id'
+
+ disable_ddl_transaction!
+
+ def up
+ remove_concurrent_index_by_name(:notes, TEMP_INDEX_NAME)
+
+ add_concurrent_index(:notes, :id, where: "noteable_type = 'Commit' AND noteable_id IS NOT NULL", name: TEMP_INDEX_NAME)
+
+ # rubocop:disable Migration/UpdateLargeTable
+ update_column_in_batches(:notes, :noteable_id, nil, batch_size: 300) do |table, query|
+ query.where(
+ table[:noteable_type].eq('Commit').and(table[:noteable_id].not_eq(nil))
+ )
+ end
+
+ remove_concurrent_index_by_name(:notes, TEMP_INDEX_NAME)
+ end
+
+ def down
+ end
+end