Add `latest_pipeline_id` column to `vulnerability_statistics` table
What does this MR do?
This MR introduces a new column called latest_pipeline_id
for the vulnerability_statistics
table along with the logic to set and query its value.
Database review
This MR introduces 3 new migrations in order;
- The one adds the
latest_pipeline_id
column - The one creates the index concurrently for the new column
- The one adds the foreign-key constraint concurrently
The second one and the third one could be merged but I think it's better to keep them separate to make it possible to run/rollback each action individually.
Also, I believe that we should implement a helper method to introduce a column with concurrent index creation along with a foreign-key constraint to eliminate the need of losing engineers within the documentation.
rake db:migrate:up
== 20210525184900 AddLatestPipelineIdIntoVulnerabilityStatisticsTable: migrating
-- add_column(:vulnerability_statistics, :latest_pipeline_id, :bigint)
-> 0.0020s
== 20210525184900 AddLatestPipelineIdIntoVulnerabilityStatisticsTable: migrated (0.0020s)
== 20210526181820 AddIndexToVulnerabilityStatisticsOnLatestPipelineId: migrating
-- transaction_open?()
-> 0.0000s
-- index_exists?(:vulnerability_statistics, :latest_pipeline_id, {:name=>"index_vulnerability_statistics_on_latest_pipeline_id", :algorithm=>:concurrently})
-> 0.0022s
-- execute("SET statement_timeout TO 0")
-> 0.0004s
-- add_index(:vulnerability_statistics, :latest_pipeline_id, {:name=>"index_vulnerability_statistics_on_latest_pipeline_id", :algorithm=>:concurrently})
-> 0.0035s
-- execute("RESET ALL")
-> 0.0004s
== 20210526181820 AddIndexToVulnerabilityStatisticsOnLatestPipelineId: migrated (0.0071s)
== 20210526181821 AddForeignKeyForLatestPipelineIdToCiPipelines: migrating ====
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:vulnerability_statistics)
-> 0.0030s
-- execute("ALTER TABLE vulnerability_statistics\nADD CONSTRAINT fk_e8b13c928f\nFOREIGN KEY (latest_pipeline_id)\nREFERENCES ci_pipelines (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0016s
-- execute("ALTER TABLE vulnerability_statistics VALIDATE CONSTRAINT fk_e8b13c928f;")
-> 0.0044s
== 20210526181821 AddForeignKeyForLatestPipelineIdToCiPipelines: migrated (0.0160s)
rake db:migrate:down
== 20210526181821 AddForeignKeyForLatestPipelineIdToCiPipelines: reverting ====
-- foreign_keys(:vulnerability_statistics)
-> 0.0030s
-- remove_foreign_key(:vulnerability_statistics, :ci_pipelines)
-> 0.0027s
== 20210526181821 AddForeignKeyForLatestPipelineIdToCiPipelines: reverted (0.0124s)
== 20210526181820 AddIndexToVulnerabilityStatisticsOnLatestPipelineId: reverting
-- transaction_open?()
-> 0.0000s
-- indexes(:vulnerability_statistics)
-> 0.0020s
-- execute("SET statement_timeout TO 0")
-> 0.0004s
-- remove_index(:vulnerability_statistics, {:algorithm=>:concurrently, :name=>"index_vulnerability_statistics_on_latest_pipeline_id"})
-> 0.0019s
-- execute("RESET ALL")
-> 0.0004s
== 20210526181820 AddIndexToVulnerabilityStatisticsOnLatestPipelineId: reverted (0.0052s)
== 20210525184900 AddLatestPipelineIdIntoVulnerabilityStatisticsTable: reverting
-- remove_column(:vulnerability_statistics, :latest_pipeline_id, :bigint)
-> 0.0015s
== 20210525184900 AddLatestPipelineIdIntoVulnerabilityStatisticsTable: reverted (0.0038s)
Related to #271408 (closed).
Does this MR meet the acceptance criteria?
Conformity
-
I have included a changelog entry, or it's not needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team