summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorHeinrich Lee Yu <heinrich@gitlab.com>2019-02-28 19:15:30 +0800
committerHeinrich Lee Yu <heinrich@gitlab.com>2019-04-06 08:29:51 +0800
commita8a4518099cceec5826bb9ea5d9e3198c5a10698 (patch)
tree16a2767d7bf1d6ee05f771586e82d6efbe75971d /db
parent8e33e7cf474b61bbc684d993d86cb5aa775a01d0 (diff)
downloadgitlab-ce-a8a4518099cceec5826bb9ea5d9e3198c5a10698.tar.gz
Clean up `noteable_id` for notes on commits58612-clean-up-notes-data
This was incorrectly set by a bug in: https://gitlab.com/gitlab-org/gitlab-ce/issues/54924 Also adds a `batch_size` option to `update_column_in_batches`
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