Skip to content
Snippets Groups Projects
Commit fb7b7225 authored by Michael Becker's avatar Michael Becker Committed by Adam Hegyi
Browse files

Synchronously add indexes for new `vulnerability_occurrences` cols

We want to drop the `vulnerability_occurrence_pipelines` table. In
order to do this, we still need the first and latest pipeline ID
stored somewhere to support the existing feature-set

The columns and asynchronous index creation were added in a
[previous MR][0]

This change adds the synchronous index migration to complete the index
creation [process][1]

Follow-up Work
---------------------------

We will need to add loose foreign keys and model association. Both of
these are blocked on this index creation

That work is tracked in the following tasks:

- #443283
- #443284

---

Related to #422382
Resolves #443282

[0]:!144697
[1]:https://docs.gitlab.com/ee/development/database/adding_database_indexes.html#create-indexes-asynchronously

Changelog: added
parent 091c13be
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ class PrepareIndexForInitialAndLatestPipelineIdToVulnerabilityOccurrences < Gitl
INITIAL_PIPELINE_INDEX = 'index_vulnerability_occurrences_on_initial_pipeline_id'
LATEST_PIPELINE_INDEX = 'index_vulnerability_occurrences_on_latest_pipeline_id'
# TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/work_items/443282
# Index created synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/145782
def up
prepare_async_index TABLE_NAME, :initial_pipeline_id, name: INITIAL_PIPELINE_INDEX
prepare_async_index TABLE_NAME, :latest_pipeline_id, name: LATEST_PIPELINE_INDEX
......
# frozen_string_literal: true
class AddIndexForInitialAndLatestPipelineIdToVulnerabilityOccurrences < Gitlab::Database::Migration[2.2]
milestone '16.10'
disable_ddl_transaction!
TABLE_NAME = :vulnerability_occurrences
INITIAL_PIPELINE_INDEX = 'index_vulnerability_occurrences_on_initial_pipeline_id'
LATEST_PIPELINE_INDEX = 'index_vulnerability_occurrences_on_latest_pipeline_id'
def up
add_concurrent_index TABLE_NAME, :initial_pipeline_id, name: INITIAL_PIPELINE_INDEX
add_concurrent_index TABLE_NAME, :latest_pipeline_id, name: LATEST_PIPELINE_INDEX
end
def down
remove_concurrent_index_by_name TABLE_NAME, INITIAL_PIPELINE_INDEX
remove_concurrent_index_by_name TABLE_NAME, LATEST_PIPELINE_INDEX
end
end
9b4af0ef1b59e1bdeba4a4a3fdf6d61be6f80d0317ca557d47483dcffb198828
\ No newline at end of file
......@@ -27268,6 +27268,10 @@ CREATE INDEX index_vulnerability_occurrences_for_issue_links_migration ON vulner
 
CREATE INDEX index_vulnerability_occurrences_for_override_uuids_logic ON vulnerability_occurrences USING btree (project_id, report_type, location_fingerprint);
 
CREATE INDEX index_vulnerability_occurrences_on_initial_pipeline_id ON vulnerability_occurrences USING btree (initial_pipeline_id);
CREATE INDEX index_vulnerability_occurrences_on_latest_pipeline_id ON vulnerability_occurrences USING btree (latest_pipeline_id);
CREATE INDEX index_vulnerability_occurrences_on_location_image ON vulnerability_occurrences USING gin (((location -> 'image'::text))) WHERE (report_type = ANY (ARRAY[2, 7]));
 
CREATE INDEX index_vulnerability_occurrences_on_location_k8s_agent_id ON vulnerability_occurrences USING gin ((((location -> 'kubernetes_resource'::text) -> 'agent_id'::text))) WHERE (report_type = 7);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment