def _task((vers,desc)): sql = ( """ INSERT INTO `%s` (version, description) VALUES ('%s','%s'); """ ) % (table, vers, desc) task = tempfile(sql) >> db_task(dbcmd) return logtask("Reverting database version to %s" % vers, logger, task)
def db_current_version(logger, dbcmd, table="_version_" ): sql = ( """ SELECT version FROM `%s` WHERE id = (SELECT MAX(id) FROM `%s` WHERE revert=0); """ ) % (table, table) task = (tempfile(sql) >> db_getvalue(dbcmd,'version')) >> ( reject_unless(NoValueFoundError('version')) ) msgs = lambda v: ["database version: %s" % v] return logresult_info(msgs, logger, task)
def init(logger, dbcmd, table="_version_" ): sql = ( """ CREATE TABLE IF NOT EXISTS `%s` ( id INT(11) AUTO_INCREMENT PRIMARY KEY, version CHAR(14), description TEXT NULL, commit CHAR(40), revert BIT DEFAULT 0 ); """ ) % (table) return logtask("Preparing database", logger, tempfile(sql) >> db_task(dbcmd) )