Skip to content

Instantly share code, notes, and snippets.

@chulkilee
Created February 26, 2015 20:51
Show Gist options
  • Save chulkilee/5e9b160a88546721e86f to your computer and use it in GitHub Desktop.
Save chulkilee/5e9b160a88546721e86f to your computer and use it in GitHub Desktop.
Update old LDAP provider name on gitlab
puts Identity.unscoped.group(:provider).count
users = User.includes(:identities).all
duplicated_providers = %w(ldap ldapmain).sort
old_provider = 'ldap'
new_provider = 'ldapmain'
users.each do |u|
next if u.identities.blank?
if u.identities.length == 1
id = u.identities.first
id.update_columns(provider: new_provider) if id.provider == old_provider
else
next if u.identities.map(&:extern_uid).uniq.length != 1
if u.identities.map(&:provider).sort == duplicated_providers
u.identities.where(provider: old_provider).delete_all
end
end
end
puts Identity.unscoped.group(:provider).count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment