Commit 221d5414 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Make commit and design user mention indexes unique

This is needed for the UPSERT to work properly since we're detecting a
unique constraint conflict on [noteable_id, note_id]

Changelog: other
parent 59e44d44
......@@ -9,6 +9,7 @@ module AlertManagement
include ShaAttribute
include Sortable
include Noteable
include Mentionable
include Gitlab::SQL::Pattern
include Presentable
include Gitlab::Utils::StrongMemoize
......
# frozen_string_literal: true
class AddUniqueCommitDesignUserMentionIndexes < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
COMMIT_INDEX_NAME = 'commit_id_and_note_id_index'
DESIGN_INDEX_NAME = 'design_user_mentions_on_design_id_and_note_id_index'
COMMIT_UNIQUE_INDEX_NAME = 'commit_user_mentions_on_commit_id_and_note_id_unique_index'
DESIGN_UNIQUE_INDEX_NAME = 'design_user_mentions_on_design_id_and_note_id_unique_index'
def up
add_concurrent_index :commit_user_mentions, [:commit_id, :note_id], unique: true, name: COMMIT_UNIQUE_INDEX_NAME
add_concurrent_index :design_user_mentions, [:design_id, :note_id], unique: true, name: DESIGN_UNIQUE_INDEX_NAME
remove_concurrent_index_by_name :commit_user_mentions, COMMIT_INDEX_NAME
remove_concurrent_index_by_name :design_user_mentions, DESIGN_INDEX_NAME
end
def down
add_concurrent_index :design_user_mentions, [:design_id, :note_id], name: DESIGN_INDEX_NAME
add_concurrent_index :commit_user_mentions, [:commit_id, :note_id], name: COMMIT_INDEX_NAME
remove_concurrent_index_by_name :design_user_mentions, DESIGN_UNIQUE_INDEX_NAME
remove_concurrent_index_by_name :commit_user_mentions, COMMIT_UNIQUE_INDEX_NAME
end
end
1092a16d742b08ef2ef5f74bdaa92bb5f9cedbdb1161ab71abe501c39b164689
\ No newline at end of file
......@@ -22895,7 +22895,7 @@ CREATE INDEX ci_builds_gitlab_monitor_metrics ON ci_builds USING btree (status,
CREATE INDEX code_owner_approval_required ON protected_branches USING btree (project_id, code_owner_approval_required) WHERE (code_owner_approval_required = true);
CREATE INDEX commit_id_and_note_id_index ON commit_user_mentions USING btree (commit_id, note_id);
CREATE UNIQUE INDEX commit_user_mentions_on_commit_id_and_note_id_unique_index ON commit_user_mentions USING btree (commit_id, note_id);
CREATE INDEX composer_cache_files_index_on_deleted_at ON packages_composer_cache_files USING btree (delete_at, id);
......@@ -22905,7 +22905,7 @@ CREATE UNIQUE INDEX dast_site_profiles_builds_on_ci_build_id ON dast_site_profil
CREATE UNIQUE INDEX design_management_designs_versions_uniqueness ON design_management_designs_versions USING btree (design_id, version_id);
CREATE INDEX design_user_mentions_on_design_id_and_note_id_index ON design_user_mentions USING btree (design_id, note_id);
CREATE UNIQUE INDEX design_user_mentions_on_design_id_and_note_id_unique_index ON design_user_mentions USING btree (design_id, note_id);
CREATE UNIQUE INDEX epic_user_mentions_on_epic_id_and_note_id_index ON epic_user_mentions USING btree (epic_id, note_id);
......@@ -10,6 +10,7 @@ module EE
include ::Redactable
include ::StripAttribute
include ::Noteable
include ::Mentionable
include ::Awardable
include ::Referable
include ::Presentable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment