In a discussion titled ‘Is it ok to update external_id on discourse database?’ under the SSO category, Nicolas_Barrera asks whether it’s safe to manually update the external_id in the Discourse database via SQL, especially when users merge accounts in their external system, resulting in a new external_id for the same user/email. He notes that because he uses require_activation, he can’t delete and recreate the user record. RGJ confirms that updating the external_id directly is technically possible but advises addressing the root cause — suggesting always using the lowest or oldest account ID during merges. Nicolas_Barrera explains that his use case is more complex: some accounts (type A) are meant for forum interaction, others (type B) are not, and merges may preserve the older (non-forum) account ID, breaking SSO. He plans to implement a daily cron job to fix mismatched external_ids temporarily. RGJ offers three alternatives: (a) synchronize all accounts via SSO sync, (b) track which accounts have logged into Discourse, or (c) use an external ID lookup during merges to identify which accounts are linked to Discourse. The consensus is that while direct SQL updates are feasible, they’re a workaround — the ideal solution involves better synchronization or tracking logic in the external system.
I 've been searching the forum for info on updating external_id on discourse db.
found this topic interesting:
Still I was interested in some insights regarding the implications of updating the external_id on the database.
could I just issue an sql update and set the new correct external_id? can that bring any hidden problems? like if the user has a current open session or something else?
I got the users created through sso using an external_id that’s the user’s account id on the external system. (I may need to model something else but it would be cool to be able to avoid changing the external system model at least for now)
the problem for me is that the person may have more than one account on the external system and can merge those accounts into one so sometimes depending on how he merges a new external_id can come for the same user/email.
I am using the require_activation option so as I 've read on the mentioned topic I can’t delete the record and wait for it to be recreated.
a) synchronize all accounts to discourse using the SSO sync mechanism
b) keep track of which accounts have been used to log in to Discourse
or
c) when you merge, do an external ID lookup to determine which account(s) have been used with Discourse