Commit ac5af614 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix-ldap-migration' into 'master'

Fix ldap migration

We need different queries for MySQL and Postgres.

See merge request !1771
parents afb43a8f 0b2670f8
...@@ -17,13 +17,26 @@ class FixIdentities < ActiveRecord::Migration ...@@ -17,13 +17,26 @@ class FixIdentities < ActiveRecord::Migration
end end
# Delete duplicate identities # Delete duplicate identities
execute "DELETE FROM identities WHERE provider = 'ldap' AND user_id IN (SELECT user_id FROM identities WHERE provider = '#{new_provider}')" # We use a sort of self-join to find rows in identities which match on
# user_id but where one has provider 'ldap'. We delete the duplicate row
# with provider 'ldap'.
delete_statement = ''
case adapter_name.downcase
when /^mysql/
delete_statement << 'DELETE FROM id1 USING identities AS id1, identities AS id2'
when 'postgresql'
delete_statement << 'DELETE FROM identities AS id1 USING identities AS id2'
else
raise "Unknown DB adapter: #{adapter_name}"
end
delete_statement << " WHERE id1.user_id = id2.user_id AND id1.provider = 'ldap' AND id2.provider = '#{new_provider}'"
execute delete_statement
# Update legacy identities # Update legacy identities
execute "UPDATE identities SET provider = '#{new_provider}' WHERE provider = 'ldap';" execute "UPDATE identities SET provider = '#{new_provider}' WHERE provider = 'ldap'"
if table_exists?('ldap_group_links') if table_exists?('ldap_group_links')
execute "UPDATE ldap_group_links SET provider = '#{new_provider}' WHERE provider IS NULL OR provider = 'ldap';" execute "UPDATE ldap_group_links SET provider = '#{new_provider}' WHERE provider IS NULL OR provider = 'ldap'"
end end
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