# HG changeset patch # User Daniele Nicolodi # Date 1309176338 -7200 # Node ID 23bfe8ed416308a3de25b8d4db2e170df87f94e9 # Parent 3d6c57b24e72c194a74a4d3a7c05ab7f8fe8ed10 Fix 2.4 to 2.5 database schema version upgrade step. diff -r 3d6c57b24e72 -r 23bfe8ed4163 src/ltpdarepo/upgrade.py --- a/src/ltpdarepo/upgrade.py Mon Jun 27 13:49:12 2011 +0200 +++ b/src/ltpdarepo/upgrade.py Mon Jun 27 14:05:38 2011 +0200 @@ -57,25 +57,34 @@ # consolidate privileges: there is no need to specify grants # both for 'localhost' and for '%' hosts. drop privileges granted - # for 'localhost' + # for hosts different than '%' curs.execute("""DELETE mysql.db FROM mysql.db, users - WHERE User=username AND Host='localhost'""") + WHERE User=username AND Host <> '%'""") # drop privileges granted explicitly on transactions tables curs.execute("""DELETE mysql.tables_priv FROM mysql.tables_priv, users WHERE User=username AND Table_name='transactions'""") - # tell mysql to reload grant tables + # reload grant tables curs.execute("FLUSH PRIVILEGES") # drop unused tables curs.execute("DROP TABLE IF EXISTS user_access") curs.execute("DROP TABLE IF EXISTS user_hosts") - # drop password column from users table in administrative + # drop 'password' column from users table in administrative # database: authentication is done using mysql database curs.execute("ALTER TABLE users DROP COLUMN password") + # for each registered database + curs.execute("SELECT db_name FROM available_dbs") + databases = [row[0] for row in curs.fetchall()] + for db in databases: + # replace 'users' table with a view + curs.execute("""DROP TABLE IF EXISTS `%s`.users""" % db) + curs.execute("""CREATE VIEW `%s`.users AS + SELECT id, username FROM `%s`.users""" % (db, DATABASE)) + conn.commit()