2 # Fix a bug where older versions of mygpo allowed users to set the
3 # UID to the same value for different devices. This is not allowed
4 # anymore by update-12.sql from January 2010, but it is needed for
5 # migrating the existing user database. -- Thomas Perl, 2010-01-19
10 if len(sys
.argv
) != 3:
11 print >>sys
.stderr
, """
12 Usage: %s [username] [database]
16 username
, database
= sys
.argv
[-2:]
17 connection
= MySQLdb
.connect(user
=username
, db
=database
)
19 cur
= connection
.cursor()
20 cur
.execute('select uid, user_id, count(*) from device'
21 +' group by uid, user_id having count(*) > 1')
22 todo
= list(cur
.fetchall())
25 cur
= connection
.cursor()
26 for uid
, user_id
, count
in todo
:
28 cur
.execute('select id from device where uid=%s and user_id=%s',
30 for row
in list(cur
.fetchall()):
33 new_uid
= '%s%d' % (uid
, counter
)
34 print 'updating uid of %s to %s' % (id, new_uid
)
35 cur
.execute('update device set uid=%s where id=%s',