Skip to content

Replace Member created state with active

Vijay Hawoldar requested to merge vij-remove-member-created-state into master

What does this MR do and why?

In #346565 (comment 754778119) we decided to remove the Member created state entirely and replace it with active.

To do this, we will need to change active to be represented by 0 in the DB, and remove references to created.

We will then run a post deployment migration to migrate any Members who have a state value of 2 to 0.

This migration will ensure that any SM customers that manually changed Member states or fiddled with the as-yet unreleased saas_user_caps feature, will have their data reset to a valid value.

These states are unused currently and at the time of writing there are current zero members on GitLab.com with a state of 2:

[ gprd ] production> Member.where(state: 2).count
=> 0

Due to this, I opted for a regular post migration rather than a background one. Although the Members table is a high traffic one, this migration should not match any records on GitLab.com, and very few on SM instances. Using a post migration means we can ensure the blocking MR that removes the state (!76653 (merged) will have been deployed first)

More info can be found in #346565 (comment 754778119)

Data migration

  • The migration is setup as not reversible because we do not need to revert any changed data if the migration fails or is rolled back. We have zero production records on GitLab.com and anticipate a very low number of records on SM because this data is only used in an unreleased and feature flagged feature.
  • If an error occurs, there would be no impact to users on SaaS (no records to update) and for SM there maybe a number of Member records which are still in an incorrect state. Re-running the migration would rectify this (assuming it succeeds).
migrate up
bin/rails db:migrate
== 20211220123956 UpdateInvalidMemberStates: migrating ========================
== 20211220123956 UpdateInvalidMemberStates: migrated (0.0307s) ===============
migrate down
 bin/rails db:rollback
== 20211220123956 UpdateInvalidMemberStates: reverting ========================
== 20211220123956 UpdateInvalidMemberStates: reverted (0.0000s) ===============

Additional conversation and initial review notes for the migration can be found in !76750 (comment 790086191) (the work subsequently moved into this MR)

How to set up and validate locally

  1. Add a user to a group
  2. Check the member state:
      Member.last.active?
      => true
      Member.last.state
      => 0 

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 Vijay Hawoldar

Merge request reports