Start storing change date for max_seats_used
What does this MR do and why?
This is foundational work for issues [SaaS] Alert to group Owners when group is appr... (#348481 - closed) and [SaaS] Seat overage email schedules excessive n... (#358080 - closed).
We want to be able to efficiently determine what date a subscription had
its max_seats_used
value updated so that we can determine whether or not
we need to inform the user of our overage policy. We've chosen to store this value so that we don't have to calculate the date the last billable user was added to a group every time a group owner loads a page in the group.
This MR will be followed up by !83492 (merged)
Migrations
AddMaxSeatsUsedChangedAtToGitlabSubscriptions
rails db:migrate:up:main VERSION=20220413235818
== 20220413235818 AddMaxSeatsUsedChangedAtToGitlabSubscriptions: migrating ====
-- add_column(:gitlab_subscriptions, :max_seats_used_changed_at, :datetime_with_timezone)
-> 0.0066s
== 20220413235818 AddMaxSeatsUsedChangedAtToGitlabSubscriptions: migrated (0.0066s)
rails db:migrate:down:main VERSION=20220413235818
== 20220413235818 AddMaxSeatsUsedChangedAtToGitlabSubscriptions: reverting ====
-- remove_column(:gitlab_subscriptions, :max_seats_used_changed_at, :datetime_with_timezone)
-> 0.0045s
== 20220413235818 AddMaxSeatsUsedChangedAtToGitlabSubscriptions: reverted (0.0114s)
How to set up and validate locally
- Ensure the instance thinks it's SaaS by starting the GDK with the flag
GITLAB_SIMULATE_SAAS=1 gdk restart
- Create a group and purchase a GitLab subscription for the group under the Billing tab
- Observe that
max_seats_used_changed_at
isnil
in the rails console - Run the worker to update the max seats used statistics
GITLAB_SIMULATE_SAAS=1 rails c ApplicationSetting.first.update!(check_namespace_plan: true) UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker.new.perform
- Observe that
max_seats_used_changed_at
is the current date in the console - Add users to the group and re-run the worker
- The
max_seats_used_changed_at
has been updated - Remove users from the group and re-run the worker
- The
max_seats_used_changed_at
has not been updated
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.