Page 1 of 1

superbasic question -- changing a user's username [RESOLVED]

PostPosted: Mon Jul 15, 2013 11:10 pm
by supra92
It seems implausible, but a search of the Help forum turned up zero posts/threads about what I would assume would be a fairly common task: changing a user's username once he/she has already been added. LOTS of questions about the admin/admin un/pw combo and about migrating users and database from install to install, but nothing about simply changing someone's name.

How exactly is this done? I've tried interacting directly with the database itself (via "db.view"), and issuing "update TABLENAME set username='newusername' where username='oldusername' " statements.... but I'm getting lots of foreign key errors when I try to do this. Trying to update the username in the USER table, it gripes about a FK in the USER_ROLE table.... but I get similar error when I try to update USER_ROLE too. Ditto for tables like Playlist, Custom_Avatar, etc -- key constraints preclude changing the username. Nor does there seem to be a way via SS's main interface itself. I try going to Settings, and then choosing a user from the dropdown..... but all I can change is the user's password, or delete the user entirely.

To answer what I'm anticipating to be a common response/question ("why don't you just delete the user and create a new one?")........... I don't want to do that because I'd like to preserve the user's info (Star ratings, reviews/comments, upload and download totals, etc.). Deleting and recreating loses all that information entirely. Plus, I don't want to have to ask the user for his/her password when recreating the account (or asking them to redo it themselves).

Renaming a user should be a simple process by the admin that should be transparent to the end user. And, I admit... it's somewhat surprising that there is not a central "User" table that contains ONLY user_id and username fields, with all other subsonic tables utilising the user_id, rather than the username itself. This is rather RDBMS/Normalisation 101 stuff, IMHO...

Anyone have any ideas?

Thanks,
Supra92

Re: superbasic question -- changing a user's username?

PostPosted: Wed Jul 17, 2013 2:12 pm
by stozher
Stop SS, open with text editor .../db/subsonic.script, find/replace... Create backup before edit!

Re: superbasic question -- changing a user's username?

PostPosted: Fri Jul 19, 2013 11:14 pm
by supra92
Hey Stozher,

Thanks for that -- worked like a charm! The idea of all that data being stored in a *text file*, and then written to the database every single time SS is restarted.... as opposed to simply being permanently in database.... didn't even occur to me. Strange, but hey... a simple "sed -i 's/oldname/newname/g' subsonic.script" and presto.

Only caveat I've seen thus far --- when you select Users to view the Upload/Download statistics/graphs, the old username appears there as well as the new one. That stuff is stored in the DB permanently, and so you have to actually go in and delete the oldname's row from that one DB table to get it to disappear from the charts. No biggie whatsoever.

Thanks again, and cheers,
Supra92