Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add oneoff script for incrementally migrating users to multi auth #27687

Merged
merged 1 commit into from Mar 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions bin/oneoff/migrate_users_to_multi_auth.rb
@@ -0,0 +1,32 @@
#!/usr/bin/env ruby

require_relative '../../dashboard/config/environment'

SLICE_SIZE = 1_000

def migrate_batches(limit=nil)
limit = limit.to_i if limit
unmigrated_users = User.where.not(provider: User::PROVIDER_MIGRATED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to with_deleted include soft-deleted users, or are we officially leaving those behind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My plan is to leave them behind, then wait 30 days after this script finishes to begin tearing out support for nonmigrated users to ensure that they are fully gone.

unmigrated_users_count = 40_000_000 # estimate
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

estimated this via an SQL select on the reporting DB.


slice_count = 0
puts "Migrating #{limit || 'all'} slice(s)"
unmigrated_users.each_slice(SLICE_SIZE) do |slice|
puts "\tSLICE_COUNT: #{slice_count + 1} of ~#{unmigrated_users_count / SLICE_SIZE}..."
ActiveRecord::Base.transaction do
successes = 0
slice.each do |user|
user.migrate_to_multi_auth
successes += 1 if user.valid? && user.provider == User::PROVIDER_MIGRATED
end
puts "\t\tsuccessful migrations: #{successes} / #{SLICE_SIZE}"
end
slice_count += 1

if limit && slice_count >= limit
break
end
end
end

migrate_batches(*ARGV)