Contents
Renaming user accounts in the database
Description
The following script renames user accounts in a SQLite database. This is particularly useful when you imported a database from Bugzilla, which uses e-mail addresses as user names, and want to use different user names in your Trac or Subversion.
The original version showed how to do it with a canned list of old and new names in the script. This version accepts an old name and a new name on the command line, making sure there are two arguments before proceeding. This seems more immediately useful to me.
#!/bin/bash if [ $# -ne 2 ] then echo "Usage: renameuser oldname newname" exit 1 fi OLDNAME=$1 NEWNAME=$2 sqlite3 trac.db <<EOF UPDATE "permission" SET username='$NEWNAME' WHERE username='$OLDNAME'; UPDATE "auth_cookie" SET name='$NEWNAME' WHERE name='$OLDNAME'; UPDATE "session" SET sid='$NEWNAME' WHERE sid='$OLDNAME'; UPDATE "session_attribute" SET sid='$NEWNAME' WHERE sid='$OLDNAME'; UPDATE "wiki" SET author='$NEWNAME' WHERE author='$OLDNAME'; UPDATE "attachment" SET author='$NEWNAME' WHERE author='$OLDNAME'; UPDATE "ticket" SET owner='$NEWNAME' WHERE owner='$OLDNAME'; UPDATE "ticket" SET owner='$NEWNAME' WHERE owner='$OLDNAME'; UPDATE "ticket" SET reporter='$NEWNAME' WHERE reporter='$OLDNAME'; UPDATE "ticket_change" SET author='$NEWNAME' WHERE author='$OLDNAME'; UPDATE "ticket_change" SET newvalue='$NEWNAME' WHERE newvalue='$OLDNAME' AND (field='qa_contact' OR field='owner' OR field='reporter'); UPDATE "ticket_change" SET oldvalue='$NEWNAME' WHERE oldvalue='$OLDNAME' AND (field='qa_contact' OR field='owner'); UPDATE "component" SET owner='$NEWNAME' WHERE owner='$OLDNAME'; EOF
Help, I'm quite new to TracWiki. Could somebody please help me with the double quote and ampersand characters? Thanks! --langec
Done, you don't need to escape them, Trac takes care of it -- Lucas Bonnet
Bugs/Feature Requests
Existing bugs and feature requests for RenameUsersScript are here.
If you have any issues, create a new ticket.
Download
Download the zipped source from here.
Source
You can check out RenameUsersScript from here using Subversion, or browse the source with Trac.
Example
$ cd trac-env/db $ rename-users
Recent Changes
[1973] by langec on 02/14/07 16:49:32
New hack RenameUsersScript, created by langec

