Persist coverage default branch
Part of #231386 (closed)
What does this MR do?
This MR tracks when a coverage is detected for the default_branch
.
It includes the following items:
-
Add new default_branch
column -
Add new index to it -
Persist the default_branch
when creating coverage data
Why are we doing this?
Today it's a pain to fetch our coverage
data per project and filter out our coverage
for the project default branch.
To solve this problem, the team decided to track when a coverage has been calculated for our default_branch
.
This will allow us to run this following query:
Ci::DailyBuildGroupReportResult.where(default_branch: true).where("(data->'coverage') IS NOT NULL")
How the feature looks like?
You can visualize how this feature looks like on the mocks.
Database Review
-----Click here for supplemental database review materials------
Column creation
$ bin/rails db:migrate
== 20201019152046 AddDefaultBranchToDailyBuildGroupReportResult: migrating ====
-- add_column(:ci_daily_build_group_report_results, :default_branch, :boolean, {:default=>false, :null=>false})
-> 0.0034s
== 20201019152046 AddDefaultBranchToDailyBuildGroupReportResult: migrated (0.0035s)
Index creation
== 20201021142812 AddIndexToCiDailyBuildGroupReportResults: migrating =========
-- transaction_open?()
-> 0.0000s
-- index_exists?(:ci_daily_build_group_report_results, [:project_id, :date], {:order=>{:date=>:desc}, :where=>"default_branch = TRUE AND (data -> 'coverage') IS NOT NULL", :name=>"index_ci_daily_build_group_report_results_on_project_and_date", :algorithm=>:concurrently})
-> 0.0019s
-- add_index(:ci_daily_build_group_report_results, [:project_id, :date], {:order=>{:date=>:desc}, :where=>"default_branch = TRUE AND (data -> 'coverage') IS NOT NULL", :name=>"index_ci_daily_build_group_report_results_on_project_and_date", :algorithm=>:concurrently})
-> 0.0025s
== 20201021142812 AddIndexToCiDailyBuildGroupReportResults: migrated (0.0046s)
Rollback column
$ bin/rails db:rollback
== 20201019152046 AddDefaultBranchToDailyBuildGroupReportResult: reverting ====
-- remove_column(:ci_daily_build_group_report_results, :default_branch, :boolean, {:default=>false, :null=>false})
-> 0.0012s
== 20201019152046 AddDefaultBranchToDailyBuildGroupReportResult: reverted (0.0047s)
Rollback index
$ bin/rails db:rollback
== 20201021142812 AddIndexToCiDailyBuildGroupReportResults: reverting =========
-- transaction_open?()
-> 0.0000s
-- indexes(:ci_daily_build_group_report_results)
-> 0.0034s
-- remove_index(:ci_daily_build_group_report_results, {:algorithm=>:concurrently, :name=>"index_ci_daily_build_group_report_results_on_project_and_date"})
-> 0.0038s
== 20201021142812 AddIndexToCiDailyBuildGroupReportResults: reverted (0.0076s)
Table information
$ bin/rails dbconsole
psql (11.7)
Type "help" for help.
gitlabhq_development=# \d ci_daily_build_group_report_results;
Table "public.ci_daily_build_group_report_results"
Column | Type | Collation | Nullable | Default
------------------+---------+-----------+----------+-----------------------------------------------------------------
id | bigint | | not null | nextval('ci_daily_build_group_report_results_id_seq'::regclass)
date | date | | not null |
project_id | bigint | | not null |
last_pipeline_id | bigint | | not null |
ref_path | text | | not null |
group_name | text | | not null |
data | jsonb | | not null |
default_branch | boolean | | not null | false
Indexes:
"ci_daily_build_group_report_results_pkey" PRIMARY KEY, btree (id)
"index_daily_build_group_report_results_unique_columns" UNIQUE, btree (project_id, ref_path, date, group_name)
"index_ci_daily_build_group_report_results_on_last_pipeline_id" btree (last_pipeline_id)
"index_ci_daily_build_group_report_results_on_project_and_date" btree (project_id, date DESC) WHERE default_branch = true AND (data -> 'coverage'::text) IS NOT NULL
Foreign-key constraints:
"fk_rails_0667f7608c" FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
"fk_rails_ee072d13b3" FOREIGN KEY (last_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry - Changelog to be included with feature flag removal.
- [-] Documentation (if required) - Documentation to be included with feature flag removal.
-
Code review guidelines - [-] Merge request performance guidelines
-
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
- [-] Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process.
- [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] 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
Edited by Max Orefice