Commit e50b0adf authored by Alex Buijs's avatar Alex Buijs

Nullify user roles with software developer value

On October 20th code was deployed to GitLab.com
which caused profile save actions from any user to
update the role attribute to a value of 0 (software
developer). From October 21st, 16:47 CEST until October
23rd, 19:11 CEST, the new signup flow experiment was
run, which forced 10% of users created in that
timeframe to pick a role. October 24th (merged October
28th, not yet deployed) a fix was created for the
unintentional saving of the role.

Solution: after the fix is deployed (check with /chatops
run auto_deploy status aac40d26), we should nullify all
oles with a value of 0. Other values are intentional and
should be kept. Unfortunately, we must also nullify roles
with a value of software developer for users created
within the timeframe the experiment was run, because,
based on the database, we cannot distinguish between
users that participated in the experiment and users in the
control group.
parent 1895f8d9
# frozen_string_literal: true
class NullifyUsersRole < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
INDEX_NAME = 'partial_index_users_updated_at_for_cleaning_mistaken_values'.freeze
DOWNTIME = false
def up
# expected updated users count is around 10K
# rubocop: disable Migration/UpdateLargeTable
add_concurrent_index(:users, :updated_at, where: 'role = 0', name: INDEX_NAME)
update_column_in_batches(:users, :role, nil) do |table, query|
query.where(table[:updated_at].lt('2019-11-05 12:08:00')).where(table[:role].eq(0))
end
remove_concurrent_index_by_name(:users, INDEX_NAME)
end
def down
# noop
end
end
---
title: Nullify user roles that have been accidentaly set to a value of 0
merge_request: 19569
author:
type: fixed
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20191104142124_nullify_users_role.rb')
describe NullifyUsersRole, :migration do
let(:users) { table(:users) }
before do
allow(Gitlab).to receive(:com?).and_return(true)
users.create!(role: 0, updated_at: '2019-11-04 12:08:00', projects_limit: 0, email: '1')
users.create!(role: 1, updated_at: '2019-11-04 12:08:00', projects_limit: 0, email: '2')
users.create!(role: 0, updated_at: '2019-11-06 12:08:00', projects_limit: 0, email: '3')
migrate!
end
it 'nullifies the role of the user with updated_at < 2019-11-05 12:08:00 and a role of 0' do
expect(users.where(role: nil).count).to eq(1)
expect(users.where(role: nil).first.email).to eq('1')
end
it 'leaves the user with role of 1' do
expect(users.where(role: 1).count).to eq(1)
expect(users.where(role: 1).first.email).to eq('2')
end
it 'leaves the user with updated_at > 2019-11-05 12:08:00' do
expect(users.where(role: 0).count).to eq(1)
expect(users.where(role: 0).first.email).to eq('3')
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment