diff options
author | Heinrich Lee Yu <heinrich@gitlab.com> | 2019-02-28 19:15:30 +0800 |
---|---|---|
committer | Heinrich Lee Yu <heinrich@gitlab.com> | 2019-03-01 14:37:11 +0800 |
commit | 347c884cb25e3ed428cf3db62e73658dc20a22b0 (patch) | |
tree | aaf18bbc956a102d2beb8ee1770370d92ba1604a /db | |
parent | d86de642d16e0f7518c7f508b5282c89128e9a58 (diff) | |
download | gitlab-ce-347c884cb25e3ed428cf3db62e73658dc20a22b0.tar.gz |
Clean up `noteable_id` for notes on commits
This was incorrectly set by a bug in:
https://gitlab.com/gitlab-org/gitlab-ce/issues/54924
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20190228092516_clean_up_noteable_id_for_notes_on_commits.rb | 33 | ||||
-rw-r--r-- | db/schema.rb | 2 |
2 files changed, 34 insertions, 1 deletions
diff --git a/db/migrate/20190228092516_clean_up_noteable_id_for_notes_on_commits.rb b/db/migrate/20190228092516_clean_up_noteable_id_for_notes_on_commits.rb new file mode 100644 index 00000000000..fe129e8f4dc --- /dev/null +++ b/db/migrate/20190228092516_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) 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 diff --git a/db/schema.rb b/db/schema.rb index e569200d12e..24a98c374ca 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190220150130) do +ActiveRecord::Schema.define(version: 20190228092516) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |