Skip to content

Draft: Migrate invalid Member states to active

Vijay Hawoldar requested to merge vij-fix-member-state-data into master

What does this MR do and why?

This adds a migration to fix invalid Member record states.

We are doing this because in !76653 (merged) we change the values representing an active state from 2 to 0, and removed the old created state in the process.

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)

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) ===============

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

  1. Change some Member records to be in the old state:
      Member.last(3).map { |m| m.update(state: 2) }
  2. Run the migration (bin/rails db:migrate)
      Member.last(3).map :state: 
      => [0, 0, 0]
  3. Confirm the members were updated to the correct state

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