Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7d249c46
Commit
7d249c46
authored
Dec 15, 2020
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change the unique index on `security_findings` table
parent
43e0d5ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
1 deletion
+38
-1
db/migrate/20201215132151_change_unique_index_on_security_findings.rb
...0201215132151_change_unique_index_on_security_findings.rb
+36
-0
db/schema_migrations/20201215132151
db/schema_migrations/20201215132151
+1
-0
db/structure.sql
db/structure.sql
+1
-1
No files found.
db/migrate/20201215132151_change_unique_index_on_security_findings.rb
0 → 100644
View file @
7d249c46
# 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
db/schema_migrations/20201215132151
0 → 100644
View file @
7d249c46
916f29e6ab89551fd785c3a8584c24b72d9002ada30d159e9ff826cb247199b5
\ No newline at end of file
db/structure.sql
View file @
7d249c46
...
...
@@ -22529,7 +22529,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
(
uu
id
);
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment