Commit 26e0f189 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'change_unique_index_on_security_findings' into 'master'

Change the unique index on `security_findings` table

See merge request gitlab-org/gitlab!50046
parents d3796d5d 00c6e85c
---
title: Change the unique index on `security_findings` table
merge_request: 50046
author:
type: changed
# frozen_string_literal: true
class ChangeUniqueIndexOnSecurityFindings < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
OLD_INDEX_NAME = 'index_security_findings_on_uuid'
NEW_INDEX_NAME = 'index_security_findings_on_uuid_and_scan_id'
disable_ddl_transaction!
class SecurityFinding < ActiveRecord::Base
include EachBatch
self.table_name = 'security_findings'
end
def up
add_concurrent_index :security_findings, [:uuid, :scan_id], unique: true, name: NEW_INDEX_NAME
remove_concurrent_index_by_name :security_findings, OLD_INDEX_NAME
end
def down
# It is very unlikely that we rollback this migration but just in case if we have to,
# we have to clear the table because there can be multiple records with the same UUID
# which would break the creation of unique index on the `uuid` column.
# We choose clearing the table because just removing the duplicated records would
# cause data inconsistencies.
SecurityFinding.each_batch(of: 10000) { |relation| relation.delete_all }
add_concurrent_index :security_findings, :uuid, unique: true, name: OLD_INDEX_NAME
remove_concurrent_index_by_name :security_findings, NEW_INDEX_NAME
end
end
916f29e6ab89551fd785c3a8584c24b72d9002ada30d159e9ff826cb247199b5
\ No newline at end of file
......@@ -22531,7 +22531,7 @@ CREATE INDEX index_security_findings_on_scanner_id ON security_findings USING bt
CREATE INDEX index_security_findings_on_severity ON security_findings USING btree (severity);
CREATE UNIQUE INDEX index_security_findings_on_uuid ON security_findings USING btree (uuid);
CREATE UNIQUE INDEX index_security_findings_on_uuid_and_scan_id ON security_findings USING btree (uuid, scan_id);
CREATE INDEX index_self_managed_prometheus_alert_events_on_environment_id ON self_managed_prometheus_alert_events USING btree (environment_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