Transfer CI/CD minutes usage when moving namespaces
Problem
CI/CD minutes are tracked at root namespace level. When we read the usage we first check if the namespace is a root one otherwise don't return any usage data.
If the current root namespace A
is moved under a different namespace (under a new root B
) we stop tracking CI/CD minutes for this previous namespace A
and start tracking for the new root B
. However, all the CI/CD minutes used during the month are "lost":
- the new root namespace
B
doesn't contain the usage of the old rootA
- usage for
A
is no longer accessible since the CI/CD minutes are not enabled for non-root namespaces
Solution
When a root namespace moves under a different root we should transfer the CI/CD minutes usage from Ci::Minutes::NamespaceMonthlyUsage
.
Proposal
# after `transferred_namespace` has been moved under `new_parent`
new_root = new_parent.root_ancestor
Ci::MinutesNamespaceMonthlyUsage.current_month.for_namespace(transferred_namespace).update_all(namespace: new_root)
We can just transfer the usage from the current month. We don't need to transfer the historical usage because that belonged under a different root.