Commit df3ad023 authored by Andreas Brandl's avatar Andreas Brandl

Merge branch 'growth-92-clean-up-bad-data-from-role' into 'master'

Nullify user roles with software developer value

Closes gitlab-org/growth/engineering#92

See merge request gitlab-org/gitlab!19569
parents 47bf8064 e50b0adf
# 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