The discussion revolves around the idea of implementing a .csv upload feature for bulk user custom field changes in Discourse. nathank initially proposed this feature, citing its usefulness for data tidy-up exercises and migrations. pfaffman suggested using the importer or API instead, but nathank explained his specific use case, which involved restoring user custom fields that had been inadvertently deleted.
selfaware suggested that a simpler upload option would be more user-friendly, and pfaffman provided clarification on the required format for the .csv file, including an example table structure.
Well, my use case is for restoring some user custom fields which I inadvertently wiped for a bunch of users (see Manipulating custom user fields from the Rails console). I’ve got the backup on a staging site, and I’ve also got them as a .csv
When you say ‘easy’ I’m guessing you mean it would take you a few hours to bash something out that would do the job. Can you give me a cost estimate?
It requires some competence with Linux / Bash in order to use it, and I’d strongly recommend doing a backup first and doing it at a quiet time as you can royally stuff up your user data if not careful. I trialled it on a staging server before using it on our production site.
You might find this Data Explorer query useful in order to get the existing data for the user_field that you are targeting:
--[params]
-- string :ucf_name = user_field_1
SELECT
user_id, value as ":ucf_name"
FROM user_custom_fields
WHERE name = :ucf_name
ORDER BY user_id asc
Note that you’ll have to remove the ' from either side of the field name in the .csv as I couldn’t work out how to stop the query including them.