Commit 41a1cb88 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Use different queries for MySQL and Postgres

I could not find a query that worked on both; these two queries look
very similar and seem to do the same thing.
parent bf7932bd
......@@ -17,7 +17,20 @@ class FixIdentities < ActiveRecord::Migration
end
# 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
execute "UPDATE identities SET provider = '#{new_provider}' WHERE provider = 'ldap';"
......
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