Changing a user's id


(Alexander Wright) #1

Hi,

My Discourse instance is authenticating against my organisation’s membership system via the discourse-oauth2-basic plugin.

It uses the membership number from the membership system as the Discourse user_id.

Now some bright person has swapped two users’ ids in the membership system, so they are now logging in to each other’s accounts. Grrrr.

Is it possible to change the user_id of an account on Discourse? I’m guessing that I’ll have to go through every table updating user_ids on both user’s posts. My approach is to do the following:

User A (user_id=1)
User B (user_id=2)

  1. Find all rows in all tables with user_id=1 and update to user_id=99999
  2. Find all rows in all tables with user_id=2 and update to user_id=1
  3. Find all rows in all tables with user_id=99999 and update to user_id=2
  4. Find the person that thinks that sharing membership ids is a good thing and educate them.

Does anyone see a problem with the above?

Cheers!


(Jeff Atwood) #2

This sounds very, very risky so proceed with caution. I agree that the ids should not have been swapped in the upstream system.


(Alexander Wright) #3

Noted. Backups all the way.

Sadly I didn’t manage to catch the nonsense before they made the upstream change.


(Alexander Wright) #4

For those worrying, I went round with a large stick, and the membership number changes have been reversed, and those responsible have promised never to do it again.

No dodgy user_id changes required. :relieved:


(Jeff Atwood) #5

image