Commit 896ea248 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Change migration to SQL

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 8666f497
class FixIdentities < ActiveRecord::Migration
def up
new_provider = Gitlab.config.ldap.servers.first.last['provider_name']
# Delete duplicate identities
Identity.connection.select_one("DELETE FROM identities WHERE provider = 'ldap' AND user_id IN (SELECT user_id FROM identities WHERE provider = '#{new_provider}')")
# Update legacy identities
Identity.where(provider: 'ldap').update_all(provider: new_provider)
execute "DELETE FROM identities WHERE provider = 'ldap' AND user_id IN (SELECT user_id FROM identities WHERE provider = '#{new_provider}')"
# Update legacy identities
execute "UPDATE identities SET provider = '#{new_provider}' WHERE provider = 'ldap';"
if defined?(LdapGroupLink)
LdapGroupLink.where('provider IS NULL').update_all(provider: new_provider)
execute "UPDATE ldap_group_links SET provider = '#{new_provider}' WHERE provider IS NULL;"
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