diff --git a/modules/Dispatch.py b/modules/Dispatch.py index 10b9c5c..617d54b 100644 --- a/modules/Dispatch.py +++ b/modules/Dispatch.py @@ -31,10 +31,10 @@ class Dispatch(Module): def db_init(self): """Set up the database tables, if they don't exist.""" - version = self.db_module_registered(self.__class__.__name__) - if (version == None): + try: db = self.get_db() - try: + version = self.db_module_registered(self.__class__.__name__) + if version is None: version = 1 cur = db.cursor(mdb.cursors.DictCursor) cur.execute(''' @@ -48,12 +48,22 @@ class Dispatch(Module): db.commit() self.db_register_module_version(self.__class__.__name__, version) - except mdb.Error as e: - db.rollback() - self.log.error("database error trying to create tables") - self.log.exception(e) - raise - finally: cur.close() + if version == 1: + version = 2 + cur = db.cursor(mdb.cursors.DictCursor) + cur.execute(''' + ALTER TABLE dispatch_item DROP PRIMARY KEY, ADD PRIMARY KEY (key_, dest) + ''') + + db.commit() + self.db_register_module_version(self.__class__.__name__, + version) + except mdb.Error as e: + db.rollback() + self.log.error("database error trying to create tables") + self.log.exception(e) + raise + finally: cur.close() def xmlrpc_init(self): """Expose dispatching interface."""