wiki:RenameUsersScript

Version 3 (modified by lbonnet@…, 8 years ago) (diff)

Fixed html escaping in SQL

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.

#!/bin/bash

for i in \
        "old1 new1"\
        "old2 new2"
do
  OLDNAME=${i% *}
  NEWNAME=${i#* }
  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 fie
ld='owner' OR field='reporter');
UPDATE "ticket_change" SET oldvalue='$NEWNAME' WHERE oldvalue='$OLDNAME' AND (field='qa_contact' OR fie
ld='owner');
UPDATE "component" SET owner='$NEWNAME' WHERE owner='$OLDNAME';
EOF
done

Help, I'm quite new to TracWiki. Could somebody please help me with the double quote and ampersand characters? Thanks! --langec

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 2007-02-14 16:49:32
New hack RenameUsersScript, created by langec

Author/Contributors

Author: langec
Contributors: