Skip to content

Add temporary column `new_amount_used` for CI minutes tracking

Fabio Pitino requested to merge increase-accuracy-ci-minutes-amount-used into master

What does this MR do and why?

Related to https://gitlab.com/gitlab-org/gitlab/-/issues/364282

In this MR we want to increase the accuracy of ci_project_monthly_usages.amount_used from 2 decimal figures to 4 decimal figures.

In doing that we add a new_amount_used column and set a trigger to keep that in sync with amount_used. In a separate MR (for release N+1) we would remove the old column and rename the new one to amount_used:

transaction do
  remove_column :amount_used
  rename_column :new_amount_used, :amount_used
   
  # check if trigger is dropped automatically or drop the trigger
  # explicitly inside the transaction.
end

Database migration

$ rails db:migrate

ci: == 20221010184839 AddNewAmountUsedToCiProjectMonthlyUsages: migrating =========
ci: -- add_column(:ci_project_monthly_usages, :new_amount_used, :decimal, {:default=>0.0, :precision=>18, :scale=>4, :null=>false, :if_not_exists=>true})
ci:    -> 0.0077s
ci: == 20221010184839 AddNewAmountUsedToCiProjectMonthlyUsages: migrated (0.0167s) 
$ rails db:rollback:ci

ci: == 20221010184839 AddNewAmountUsedToCiProjectMonthlyUsages: reverting =========
ci: -- remove_column(:ci_project_monthly_usages, :new_amount_used)
ci:    -> 0.0014s
ci: == 20221010184839 AddNewAmountUsedToCiProjectMonthlyUsages: reverted (0.0065s) 

Data migration

TODO

  • Create same migration for ci_namespace_monthly_usages
  • Create background/post-deployment migration to SET new_amount_used = amount_used for existing records (in batches)

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Fabio Pitino

Merge request reports