Commit 1588893c authored by Nick Thomas's avatar Nick Thomas

Merge branch '270093-add-primary-key-to-mrcc-diff-files' into 'master'

Add primary key to mrcc_diff_files table

See merge request gitlab-org/gitlab!49024
parents 429b4b8f b34e4453
---
title: Add primary key to merge_request_context_commit_diff_files
merge_request: 49024
author:
type: changed
# frozen_string_literal: true
class AddPrimaryKeyToMergeRequestContextCommitDiffFiles < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
execute(<<~SQL)
DELETE FROM merge_request_context_commit_diff_files
WHERE merge_request_context_commit_id IS NULL;
DELETE FROM merge_request_context_commit_diff_files df1
USING merge_request_context_commit_diff_files df2
WHERE df1.ctid < df2.ctid
AND df1.merge_request_context_commit_id = df2.merge_request_context_commit_id
AND df1.relative_order = df2.relative_order;
ALTER TABLE merge_request_context_commit_diff_files
ADD CONSTRAINT merge_request_context_commit_diff_files_pkey PRIMARY KEY (merge_request_context_commit_id, relative_order);
SQL
end
def down
execute(<<~SQL)
ALTER TABLE merge_request_context_commit_diff_files
DROP CONSTRAINT merge_request_context_commit_diff_files_pkey,
ALTER COLUMN merge_request_context_commit_id DROP NOT NULL
SQL
end
end
# frozen_string_literal: true
class RemoveRedundantIndexOnMergeRequestContextCommitDiffFiles < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
remove_concurrent_index_by_name :merge_request_context_commit_diff_files, 'idx_mr_cc_diff_files_on_mr_cc_id'
end
def down
# no-op: this index is not tracked in structure.sql, and is redundant due to idx_mr_cc_diff_files_on_mr_cc_id_and_sha
end
end
926f54b5756fa9495e71f2340823418b5679195d5720212dddda0d0c6396629e
\ No newline at end of file
696c1d9f8cc90337549530e129e6abf4429d218f151cefaacacacb6e3f33d1c7
\ No newline at end of file
......@@ -13695,7 +13695,7 @@ CREATE TABLE merge_request_context_commit_diff_files (
old_path text NOT NULL,
diff text,
"binary" boolean,
merge_request_context_commit_id bigint
merge_request_context_commit_id bigint NOT NULL
);
CREATE TABLE merge_request_context_commits (
......@@ -19550,6 +19550,9 @@ ALTER TABLE ONLY merge_request_blocks
ALTER TABLE ONLY merge_request_cleanup_schedules
ADD CONSTRAINT merge_request_cleanup_schedules_pkey PRIMARY KEY (merge_request_id);
ALTER TABLE ONLY merge_request_context_commit_diff_files
ADD CONSTRAINT merge_request_context_commit_diff_files_pkey PRIMARY KEY (merge_request_context_commit_id, relative_order);
ALTER TABLE ONLY merge_request_context_commits
ADD CONSTRAINT merge_request_context_commits_pkey PRIMARY KEY (id);
......
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