diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /db/migrate/20201202155913_add_primary_key_to_merge_request_context_commit_diff_files.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'db/migrate/20201202155913_add_primary_key_to_merge_request_context_commit_diff_files.rb')
-rw-r--r-- | db/migrate/20201202155913_add_primary_key_to_merge_request_context_commit_diff_files.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/db/migrate/20201202155913_add_primary_key_to_merge_request_context_commit_diff_files.rb b/db/migrate/20201202155913_add_primary_key_to_merge_request_context_commit_diff_files.rb new file mode 100644 index 00000000000..90c7b2731c8 --- /dev/null +++ b/db/migrate/20201202155913_add_primary_key_to_merge_request_context_commit_diff_files.rb @@ -0,0 +1,31 @@ +# 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 |