Skip to content

Fix amount_used column precision on ci_project_monthly_usages table

Kasia Misirli requested to merge 382386/Rename_amount_used_column_step_1 into master

What does this MR do and why?

Parent issue: https://gitlab.com/gitlab-org/gitlab/-/issues/382386
This MR is one of 2 to address the above issue. Other MR can be found here.

Adding following migrations:
20221221171239 Rename amount used column
20221222092958 Sync new amount used with amount used
20230104103748 Remove new amount used column
\

Migrations logs:

Migration: 20221221171239 Rename amount used column
on CI database:
UP

✗ rake db:migrate:up:ci VERSION=20221221171239
ci: == 20221221171239 RenameAmountUsedColumn: migrating ===========================
ci: -- rename_column(:ci_project_monthly_usages, :amount_used, :tmp_amount_used)
ci:    -> 0.0728s
ci: -- rename_column(:ci_project_monthly_usages, :new_amount_used, :amount_used)
ci:    -> 0.0021s
ci: -- rename_column(:ci_project_monthly_usages, :tmp_amount_used, :new_amount_used)
ci:    -> 0.0018s
ci: == 20221221171239 RenameAmountUsedColumn: migrated (0.0883s) ==================

DOWN

 ✗ rake db:migrate:down:ci VERSION=20221221171239
ci: == 20221221171239 RenameAmountUsedColumn: reverting ===========================
ci: -- rename_column(:ci_project_monthly_usages, :amount_used, :tmp_amount_used)
ci:    -> 0.0717s
ci: -- rename_column(:ci_project_monthly_usages, :new_amount_used, :amount_used)
ci:    -> 0.0021s
ci: -- rename_column(:ci_project_monthly_usages, :tmp_amount_used, :new_amount_used)
ci:    -> 0.0018s
ci: == 20221221171239 RenameAmountUsedColumn: reverted (0.0897s) ==================

on MAIN database:
UP

✗ rake db:migrate:up:main VERSION=20221221171239
main: == 20221221171239 RenameAmountUsedColumn: migrating ===========================
main: -- rename_column(:ci_project_monthly_usages, :amount_used, :tmp_amount_used)
main:    -> 0.0947s
main: -- rename_column(:ci_project_monthly_usages, :new_amount_used, :amount_used)
main:    -> 0.0023s
main: -- rename_column(:ci_project_monthly_usages, :tmp_amount_used, :new_amount_used)
main:    -> 0.0024s
main: == 20221221171239 RenameAmountUsedColumn: migrated (0.1072s) ==================

DOWN

 ✗ rake db:migrate:down:main VERSION=20221221171239
main: == 20221221171239 RenameAmountUsedColumn: reverting ===========================
main: -- rename_column(:ci_project_monthly_usages, :amount_used, :tmp_amount_used)
main:    -> 0.0895s
main: -- rename_column(:ci_project_monthly_usages, :new_amount_used, :amount_used)
main:    -> 0.0023s
main: -- rename_column(:ci_project_monthly_usages, :tmp_amount_used, :new_amount_used)
main:    -> 0.0018s
main: == 20221221171239 RenameAmountUsedColumn: reverted (0.0992s) ==================

Post-deployment migration: 20221222092958 Sync new amount used with amount used
on CI database:
UP

✗ rake db:migrate:up:ci VERSION=20221222092958
ci: == 20221222092958 SyncNewAmountUsedWithAmountUsed: migrating ==================
ci: == 20221222092958 SyncNewAmountUsedWithAmountUsed: migrated (0.0113s) =========

DOWN

 ✗ rake db:migrate:down:ci VERSION=20221222092958
ci: == 20221222092958 SyncNewAmountUsedWithAmountUsed: reverting ==================
ci: == 20221222092958 SyncNewAmountUsedWithAmountUsed: reverted (0.0247s) =========

on MAIN database:
UP

✗ rake db:migrate:up:main VERSION=20221222092958
main: == 20221222092958 SyncNewAmountUsedWithAmountUsed: migrating ==================
main: -- The migration is skipped since it modifies the schemas: [:gitlab_ci].
main: -- This database can only apply migrations in one of the following schemas: [:gitlab_main, :gitlab_shared, :gitlab_internal, :gitlab_pm].
main: == 20221222092958 SyncNewAmountUsedWithAmountUsed: migrated (0.0009s) =========

DOWN

✗ rake db:migrate:down:main VERSION=20221222092958
main: == 20221222092958 SyncNewAmountUsedWithAmountUsed: reverting ==================
main: -- The migration is skipped since it modifies the schemas: [:gitlab_ci].
main: -- This database can only apply migrations in one of the following schemas: [:gitlab_main, :gitlab_shared, :gitlab_internal, :gitlab_pm].
main: == 20221222092958 SyncNewAmountUsedWithAmountUsed: reverted (0.0009s) =========

Post-deployment migration: 20230104103748 Remove new amount used column
on CI database:
UP

 ✗ rake db:migrate:up:ci VERSION=20230104103748  
ci: == 20230104103748 RemoveNewAmountUsedColumn: migrating ========================
ci: -- remove_column(:ci_project_monthly_usages, :new_amount_used)
ci:    -> 0.0012s
ci: == 20230104103748 RemoveNewAmountUsedColumn: migrated (0.0152s) ===============

DOWN

✗ rake db:migrate:down:ci VERSION=20230104103748
ci: == 20230104103748 RemoveNewAmountUsedColumn: reverting ========================
ci: -- column_exists?(:ci_project_monthly_usages, :new_amount_used)
ci:    -> 0.0790s
ci: -- add_column(:ci_project_monthly_usages, :new_amount_used, :decimal, {:default=>0.0, :precision=>18, :scale=>2, :null=>false})
ci:    -> 0.0014s
ci: == 20230104103748 RemoveNewAmountUsedColumn: reverted (0.1129s) ===============

on MAIN database:
UP

 ✗ rake db:migrate:up:main VERSION=20230104103748
main: == 20230104103748 RemoveNewAmountUsedColumn: migrating ========================
main: -- remove_column(:ci_project_monthly_usages, :new_amount_used)
main:    -> 0.0015s
main: == 20230104103748 RemoveNewAmountUsedColumn: migrated (0.0046s) ===============

DOWN

 ✗ rake db:migrate:down:main VERSION=20230104103748
main: == 20230104103748 RemoveNewAmountUsedColumn: reverting ========================
main: -- column_exists?(:ci_project_monthly_usages, :new_amount_used)
main:    -> 0.1108s
main: -- add_column(:ci_project_monthly_usages, :new_amount_used, :decimal, {:default=>0.0, :precision=>18, :scale=>2, :null=>false})
main:    -> 0.0021s
main: == 20230104103748 RemoveNewAmountUsedColumn: reverted (0.1183s) ===============

How to set up and validate locally

Checkout the branch and run the migration on ci and main db.

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 Kasia Misirli

Merge request reports