Changing custom user field ID#

(Denis Heraud) #1

We had our webmaster adjust our SSO to pass data to some custom user fields. Sadly he didn’t assign them the right field ID’s. Is there any way that I, on my end, can change our custom user field ID’s in (or out) of Discourse?

I tried deleting all of our user fields and starting over thinking they would reset and start at 1, but unfortunately they start at 6 instead (since I had previously created 5 user fields).

i.e. "user_fields":[{"id":6,"name":"Membership Type","description":"Membership Type"...

EDIT: On a side note, why isn’t this information visible in the Admin interface? If I’m creating a bunch of user fields, how would I even know what their ID is in the first place? The 1,2,3,4… convention only really works if you a) never delete a user field; and b) never move a user field up or down.

EDIT 2: Maybe these can be changed through Rails?

(Régis Hanol) #3

Why do you need the user_fied id for?

(Denis Heraud) #4

How else would I direct values from the SSO payload unless I knew what the field ID’s were?

(Régis Hanol) #5

Right. I’m not familiar with that part of the code.

I agree that if we’re using the id to store their value, it should be visible somewhere.

As for the original question, you’ll have to reset the counter with some SQL

ALTER SEQUENCE user_fields_id_seq RESTART WITH 1;

(Denis Heraud) #6

Thank you @zogstrip ! Now would that reset the counter for existing fields, or subsequently created fields?

I presume I would have to delete my fields, run the command, and recreate them in the right order?

(Régis Hanol) #7

That’ll reset the counter on the table. So it will only be used for subsequently created fields.

(Denis Heraud) #8

Just did it and it worked perfectly! Many thanks!