changeset 16:23bfe8ed4163

Fix 2.4 to 2.5 database schema version upgrade step.
author Daniele Nicolodi <daniele@grinta.net>
date Mon, 27 Jun 2011 14:05:38 +0200
parents 3d6c57b24e72
children b63f74313bab
files src/ltpdarepo/upgrade.py
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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()