Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mitio/40aee346bef2489f7fef to your computer and use it in GitHub Desktop.
Save mitio/40aee346bef2489f7fef to your computer and use it in GitHub Desktop.
Link the new google-oauth2 logins of ambassadors who previously used the deprecated google auth login.
-- Check for mismatched social auths due to migration from google to google-oauth2
SELECT
usa.id AS auth_id,
u.id AS ambassador_user_id,
u.username AS ambassador_user,
u.first_name AS ambassador_name,
u.last_name AS ambassador_surname,
u.email AS ambassador_email,
u2.id AS user_id,
u2.username,
u2.first_name,
u2.last_name,
u2.email
FROM
social_auth_usersocialauth usa
JOIN auth_user u ON u.email = usa.uid
JOIN auth_user_groups ug ON ug.user_id = u.id AND ug.group_id = 1
JOIN auth_user u2 ON u2.id = usa.user_id
LEFT OUTER JOIN auth_user_groups ug2 ON ug2.user_id = usa.user_id AND ug2.group_id = 1
WHERE
usa.provider = 'google-oauth2'
AND ug2.id IS NULL
;
-- Fix mismatched social auths due to migration from google to google-oauth2
UPDATE
social_auth_usersocialauth usa
JOIN auth_user u ON u.email = usa.uid
JOIN auth_user_groups ug ON ug.user_id = u.id AND ug.group_id = 1
JOIN auth_user u2 ON u2.id = usa.user_id
LEFT OUTER JOIN auth_user_groups ug2 ON ug2.user_id = usa.user_id AND ug2.group_id = 1
SET
usa.user_id = u.id
WHERE
usa.provider = 'google-oauth2'
AND ug2.id IS NULL
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment