def upgrade(self): self.env.log.debug("T&E Checking for custom_report upgrade") # Check to see what version we have version = tryint(dbhelper.get_system_value(self.env, self.name)) if version > self.version: raise TracError("Fatal Error: You appear to be running two plugins with" " conflicting versions of the CustomReportManager class." " Please ensure that '%s' is updated to " "version %s of the file reportmanager.py (currently using version %s)." % (__name__, str(self.version), str(version))) # Do the staged updates, I removed this: version < 1 and if not dbhelper.db_table_exists(self.env, 'custom_report'): dbhelper.execute_non_query( self.env, "CREATE TABLE custom_report (" "id INTEGER," "uuid VARCHAR(64)," "maingroup VARCHAR(255)," "subgroup VARCHAR(255)," "version INTEGER," "ordering INTEGER)") #if version < 2: # Updates complete, set the version dbhelper.set_system_value(self.env, self.name, self.version) self.env.log.debug("T&E END Checking for custom_report upgrade")
def db_do_upgrade(self): print "Beginning DB Upgrade" tables = dbhelper.get_database_table_names(self.env.get_db_cnx()) bill_date = [table for table in tables if table == 'bill_date'] report_version = [ table for table in tables if table == 'report_version' ] if not bill_date: print "Creating bill_date table" sql = """ CREATE TABLE bill_date ( time integer, set_when integer, str_value text ); """ dbhelper.execute_non_query(self.env.get_db_cnx(), sql) if not report_version: print "Creating report_version table" sql = """ CREATE TABLE report_version ( report integer, version integer, UNIQUE (report, version) ); """ dbhelper.execute_non_query(self.env.get_db_cnx(), sql)
def delete_ticket_change( comp, ticket_id, author, change_time, field): """ removes a ticket change from the database """ if isinstance(change_time, datetime.datetime): change_time = to_timestamp(change_time) sql = """DELETE FROM ticket_change WHERE ticket=%s and author=%s and time=%s and field=%s""" dbhelper.execute_non_query(comp.env, sql, ticket_id, author, change_time, field)
def upgrade(self): self.env.log.debug("T&E Checking for custom_report upgrade") # Check to see what version we have version = tryint(dbhelper.get_system_value(self.env, self.name)) if version > self.version: raise TracError( "Fatal Error: You appear to be running two plugins with" " conflicting versions of the CustomReportManager class." " Please ensure that '%s' is updated to " "version %s of the file reportmanager.py (currently using version %s)." % (__name__, str(self.version), str(version))) # Do the staged updates, I removed this: version < 1 and if not dbhelper.db_table_exists(self.env, 'custom_report'): dbhelper.execute_non_query( self.env, "CREATE TABLE custom_report (" "id INTEGER," "uuid VARCHAR(64)," "maingroup VARCHAR(255)," "subgroup VARCHAR(255)," "version INTEGER," "ordering INTEGER)") #if version < 2: # Updates complete, set the version dbhelper.set_system_value(self.env, self.name, self.version) self.env.log.debug("T&E END Checking for custom_report upgrade")
def db_do_upgrade(self): print "Beginning DB Upgrade" tables = dbhelper.get_database_table_names(self.env.get_db_cnx()) bill_date = [table for table in tables if table == 'bill_date'] report_version = [table for table in tables if table == 'report_version'] if not bill_date: print "Creating bill_date table" sql = """ CREATE TABLE bill_date ( time integer, set_when integer, str_value text ); """ dbhelper.execute_non_query(self.env.get_db_cnx(), sql) if not report_version: print "Creating report_version table" sql = """ CREATE TABLE report_version ( report integer, version integer, UNIQUE (report, version) ); """ dbhelper.execute_non_query(self.env.get_db_cnx(), sql)
def insert_report_version(id, ver): sql = "DELETE FROM report_version WHERE report = %s;" dbhelper.execute_non_query(self.env.get_db_cnx(), sql, id) sql = """ INSERT INTO report_version (report, version) VALUES (%s, %s);""" # print "about to insert report_version" dbhelper.execute_non_query(self.env.get_db_cnx(), sql, id, ver)
def insert_report_version(id, ver): sql = "DELETE FROM report_version WHERE report = %s;" dbhelper.execute_non_query(self.env.get_db_cnx(), sql, id ) sql = """ INSERT INTO report_version (report, version) VALUES (%s, %s);""" # print "about to insert report_version" dbhelper.execute_non_query(self.env.get_db_cnx(), sql, id, ver )
def do_user_man_update(self): sql = """ INSERT INTO wiki (name,version,time,author,ipnr,text,comment,readonly) VALUES ( %s, %s, strftime('%%s', 'now', 'unixepoch', 'localtime'), 'Timing and Estimation Plugin', '127.0.0.1', %s,'',0) """ dbhelper.execute_non_query(self.env.get_db_cnx(), sql, user_manual_wiki_title, user_manual_version, user_manual_content)
def delete_ticket_change(comp, ticket_id, author, change_time, field): """ removes a ticket change from the database """ if isinstance(change_time, datetime.datetime): change_time = to_timestamp(change_time) sql = """DELETE FROM ticket_change WHERE ticket=%s and author=%s and time=%s and field=%s""" dbhelper.execute_non_query(comp.env, sql, ticket_id, author, change_time, field)
def do_user_man_update(self): sql = """ INSERT INTO wiki (name,version,time,author,ipnr,text,comment,readonly) VALUES ( %s, %s, strftime('%%s', 'now', 'unixepoch', 'localtime'), 'Timing and Estimation Plugin', '127.0.0.1', %s,'',0) """ dbhelper.execute_non_query(self.env.get_db_cnx(),sql, user_manual_wiki_title, user_manual_version, user_manual_content)
def do_db_upgrade(self): # Legacy support hack (supports upgrades from 0.1.6 to 0.1.7) if self.db_installed_version == 0: bill_date = dbhelper.db_table_exists(self, 'bill_date'); report_version = dbhelper.db_table_exists(self, 'report_version'); if bill_date and report_version: self.db_installed_version = 1 # End Legacy support hack if self.db_installed_version < 1: print "Creating bill_date table" sql = """ CREATE TABLE bill_date ( time integer, set_when integer, str_value text ); """ dbhelper.execute_non_query(self, sql) print "Creating report_version table" sql = """ CREATE TABLE report_version ( report integer, version integer, UNIQUE (report, version) ); """ dbhelper.execute_non_query(self, sql) if self.db_installed_version < 4: print "Upgrading report_version table to v4" sql =""" ALTER TABLE report_version ADD COLUMN tags varchar(1024) null; """ dbhelper.execute_non_query(self, sql) if self.db_installed_version < 5: # In this version we convert to using reportmanager.py # The easiest migration path is to remove all the reports!! # They will be added back in later but all custom reports will be lost (deleted) print "Dropping report_version table" sql = "DELETE FROM report " \ "WHERE author=%s AND id IN (SELECT report FROM report_version)" dbhelper.execute_non_query(self, sql, 'Timing and Estimation Plugin') sql = "DROP TABLE report_version" dbhelper.execute_non_query(self, sql) #version 6 upgraded reports # This statement block always goes at the end this method dbhelper.set_system_value(self, self.db_version_key, self.db_version) self.db_installed_version = self.db_version
def do_user_man_update(self): when = int(time.time()) sql = """ INSERT INTO wiki (name,version,time,author,ipnr,text,comment,readonly) VALUES ( %s, %s, %s, 'Timing and Estimation Plugin', '127.0.0.1', %s,'',0) """ dbhelper.execute_non_query(self, sql, user_manual_wiki_title, user_manual_version, when, user_manual_content)
def do_db_upgrade(self): # Legacy support hack (supports upgrades from 0.1.6 to 0.1.7) if self.db_installed_version == 0: bill_date = dbhelper.db_table_exists(self, 'bill_date') report_version = dbhelper.db_table_exists(self, 'report_version') if bill_date and report_version: self.db_installed_version = 1 # End Legacy support hack if self.db_installed_version < 1: print "Creating bill_date table" sql = """ CREATE TABLE bill_date ( time integer, set_when integer, str_value text ); """ dbhelper.execute_non_query(self, sql) print "Creating report_version table" sql = """ CREATE TABLE report_version ( report integer, version integer, UNIQUE (report, version) ); """ dbhelper.execute_non_query(self, sql) if self.db_installed_version < 4: print "Upgrading report_version table to v4" sql = """ ALTER TABLE report_version ADD COLUMN tags varchar(1024) null; """ dbhelper.execute_non_query(self, sql) if self.db_installed_version < 5: # In this version we convert to using reportmanager.py # The easiest migration path is to remove all the reports!! # They will be added back in later but all custom reports will be lost (deleted) print "Dropping report_version table" sql = "DELETE FROM report " \ "WHERE author=%s AND id IN (SELECT report FROM report_version)" dbhelper.execute_non_query(self, sql, 'Timing and Estimation Plugin') sql = "DROP TABLE report_version" dbhelper.execute_non_query(self, sql) #version 6 upgraded reports # This statement block always goes at the end this method dbhelper.set_system_value(self, self.db_version_key, self.db_version) self.db_installed_version = self.db_version
def set_bill_date(self, username="******", when=0): now = time.time() if not when: when = now when = int(when) now = int(now) sql = """ INSERT INTO bill_date (time, set_when, str_value) VALUES (%s, %s, strftime('%m/%d/%Y %H:%M:%S',%s, 'unixepoch', 'localtime')) """ dbhelper.execute_non_query(self.env.get_db_cnx(), sql, when, now, when)
def set_bill_date(self, username="******", when=0): now = trac.util.datefmt.to_datetime(None)#get now if not when: when = now strwhen = "%s-%s-%s %#02d:%#02d:%#02d" % \ (when.year, when.month, when.day, when.hour,when.minute, when.second) sql = """ INSERT INTO bill_date (time, set_when, str_value) VALUES (%s, %s, %s) """ dbhelper.execute_non_query(self.env, sql, trac.util.datefmt.to_timestamp(when), trac.util.datefmt.to_timestamp(now), strwhen)
def do_user_man_update(self): self.log.debug( "T&E Beginning User Manual Upgrade"); when = int(time.time()) sql = """ INSERT INTO wiki (name,version,time,author,ipnr,text,comment,readonly) VALUES ( %s, %s, %s, 'Timing and Estimation Plugin', '127.0.0.1', %s,'',0) """ dbhelper.execute_non_query(self.env, sql, user_manual_wiki_title, user_manual_version, when, user_manual_content) self.log.debug( "T&E End User Manual Upgrade");
def set_bill_date(self, username="******", when=0): now = time.time() if not when: when = now when = int(when) now = int(now) dtwhen = datetime.datetime.fromtimestamp(when); strwhen = "%s-%s-%s %#02d:%#02d:%#02d" % \ (dtwhen.year, dtwhen.month, dtwhen.day, dtwhen.hour,dtwhen.minute, dtwhen.second) sql = """ INSERT INTO bill_date (time, set_when, str_value) VALUES (%s, %s, %s) """ dbhelper.execute_non_query(self, sql, when, now, strwhen)
def set_bill_date(self, username="******", when=None): now = trac.util.datefmt.to_datetime(None) #get now if isinstance(when, str) or isinstance(when, unicode): when = parsetime(when, now.tzinfo) if not when: when = now strwhen = "%#04d-%#02d-%#02d %#02d:%#02d:%#02d" % \ (when.year, when.month, when.day, when.hour,when.minute, when.second) sql = """ INSERT INTO bill_date (time, set_when, str_value) VALUES (%s, %s, %s) """ dbhelper.execute_non_query(self.env, sql, trac.util.datefmt.to_timestamp(when), trac.util.datefmt.to_timestamp(now), strwhen)
def do_user_man_update(self): self.log.debug("T&E Beginning User Manual Upgrade") when = int(time.time()) if parse_version(trac.__version__) > parse_version('1.3'): sql = """ INSERT INTO wiki (name,version,time,author,text,comment,readonly) VALUES ( %s, %s, %s, 'Timing and Estimation Plugin', %s,'',0) """ else: sql = """ INSERT INTO wiki (name,version,time,author,ipnr,text,comment,readonly) VALUES ( %s, %s, %s, 'Timing and Estimation Plugin', '127.0.0.1', %s,'',0) """ dbhelper.execute_non_query(self.env, sql, user_manual_wiki_title, user_manual_version, when, user_manual_content) self.log.debug("T&E End User Manual Upgrade")
def do_db_upgrade(self): self.log.debug( "T&E Beginning DB Upgrade"); if self.db_installed_version < 1: if not dbhelper.db_table_exists(self.env, 'bill_date'): print "Creating bill_date table" sql = """ CREATE TABLE bill_date ( time integer, set_when integer, str_value text );""" dbhelper.execute_non_query(self.env, sql) if self.db_installed_version < 5: # In this version we convert to using reportmanager.py # The easiest migration path is to remove all the reports!! # They will be added back in later but all custom reports will be lost (deleted) if dbhelper.db_table_exists(self.env, 'report_version'): print "Dropping report_version table" sql = "DELETE FROM report " \ "WHERE author=%s AND id IN (SELECT report FROM report_version)" dbhelper.execute_non_query(self.env, sql, 'Timing and Estimation Plugin') sql = "DROP TABLE report_version" dbhelper.execute_non_query(self.env, sql) #version 6 upgraded reports # This statement block always goes at the end this method dbhelper.set_system_value(self.env, self.db_version_key, self.db_version) self.db_installed_version = self.db_version self.log.debug( "T&E End DB Upgrade");
def do_db_upgrade(self): if self.db_installed_version < 1: print "Creating bill_date table" sql = """ CREATE TABLE bill_date ( time integer, set_when integer, str_value text ); """ dbhelper.execute_non_query(self, sql) if self.db_installed_version < 5: if dbhelper.db_table_exists(self, 'report_version'): print "Dropping report_version table" sql = "DELETE FROM report " \ "WHERE author=%s AND id IN (SELECT report FROM report_version)" dbhelper.execute_non_query(self, sql, 'Timing and Estimation Plugin') sql = "DROP TABLE report_version" dbhelper.execute_non_query(self, sql) #version 6 upgraded reports if self.db_installed_version < 7: field_settings = "field settings" self.config.set( field_settings, "fields", "billable, totalhours, hours, estimatedhours, internal") self.config.set(field_settings, "billable.permission", "TIME_VIEW:hide, TIME_RECORD:disable") self.config.set(field_settings, "hours.permission", "TIME_VIEW:remove, TIME_RECORD:disable") self.config.set(field_settings, "estimatedhours.permission", "TIME_RECORD:disable") self.config.set(field_settings, "internal.permission", "TIME_RECORD:hide") # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # This statement block always goes at the end this method dbhelper.set_system_value(self, self.db_version_key, self.db_version) self.db_installed_version = self.db_version
def do_db_upgrade(self): self.log.debug( "T&E Beginning DB Upgrade"); if self.db_installed_version < 1: if not dbhelper.db_table_exists(self.env, 'bill_date'): print "Creating bill_date table" sql = """ CREATE TABLE bill_date ( time integer, set_when integer, str_value text );""" dbhelper.execute_non_query(self.env, sql) if self.db_installed_version < 5: if dbhelper.db_table_exists(self.env, 'report_version'): print "Dropping report_version table" sql = "DELETE FROM report " \ "WHERE author=%s AND id IN (SELECT report FROM report_version)" dbhelper.execute_non_query(self.env, sql, 'Timing and Estimation Plugin') sql = "DROP TABLE report_version" dbhelper.execute_non_query(self.env, sql) #version 6 upgraded reports if self.db_installed_version < 7: field_settings = "field settings" self.config.set( field_settings, "fields", "billable, totalhours, hours, estimatedhours, internal" ) self.config.set( field_settings, "billable.permission", "TIME_VIEW:hide, TIME_RECORD:disable" ) self.config.set( field_settings, "hours.permission", "TIME_VIEW:remove, TIME_RECORD:disable" ) self.config.set( field_settings, "estimatedhours.permission", "TIME_RECORD:disable" ) self.config.set( field_settings, "internal.permission", "TIME_RECORD:hide") # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # This statement block always goes at the end this method dbhelper.set_system_value(self.env, self.db_version_key, self.db_version) self.db_installed_version = self.db_version
def do_reports_upgrade(self): print "Beginning Reports Upgrade" #make version hash _versions = dbhelper.get_result_set(self.env.get_db_cnx(), """ SELECT report as id, version, r.title as title FROM report_version JOIN report r ON r.Id = report_version.report """) versions = {} for (id, version, title) in _versions.rows: versions[title] = (id, version) biggestId = dbhelper.get_scalar(self.env.get_db_cnx(), "SELECT ID FROM report ORDER BY ID DESC LIMIT 1") def insert_report_version(id, ver): sql = "DELETE FROM report_version WHERE report = %s;" dbhelper.execute_non_query(self.env.get_db_cnx(), sql, id ) sql = """ INSERT INTO report_version (report, version) VALUES (%s, %s);""" # print "about to insert report_version" dbhelper.execute_non_query(self.env.get_db_cnx(), sql, id, ver ) # print "inserted report_version" for report_group in all_reports: rlist = report_group["reports"] for report in rlist: title = report["title"] new_version = report["version"] report_id = [rid for (rid, map_title) in self.reportmap if map_title == title] if not report_id: bit = True; sql = """INSERT INTO report (id,author,title,query,description) VALUES (%s,'Timing and Estimation Plugin',%s,%s,'') """ biggestId += 1 dbhelper.execute_non_query(self.env.get_db_cnx(), sql, biggestId, title, report["sql"]) insert_report_version(biggestId, new_version) report["reportnumber"] = biggestId self.reportmap.extend([(biggestId,title)]) else: report_id = report_id[0] report["reportnumber"] = report_id # If we had a report make sure its at the correct version if versions.has_key(title): ( _ , ver) = versions[title] else: ver = 0 if not ver: sql = """ UPDATE report SET query=%s WHERE id = %s """ print "updating report: %s" % title dbhelper.execute_non_query(self.env.get_db_cnx(), sql, report["sql"], report_id ) insert_report_version( report_id, new_version ) elif ver < new_version: sql = """ UPDATE report SET query=%s WHERE id = %s """ print "updating report to new version: %s" % title dbhelper.execute_non_query(self.env.get_db_cnx(), sql, report["sql"], report_id ) sql = """ UPDATE report_version SET version = %s WHERE report = %s """ dbhelper.execute_non_query(self.env.get_db_cnx(), sql, new_version, report_id)
def do_reports_upgrade(self): print "Beginning Reports Upgrade" #make version hash _versions = dbhelper.get_result_set( self.env.get_db_cnx(), """ SELECT report as id, version, r.title as title FROM report_version JOIN report r ON r.Id = report_version.report """) versions = {} for (id, version, title) in _versions.rows: versions[title] = (id, version) biggestId = dbhelper.get_scalar( self.env.get_db_cnx(), "SELECT ID FROM report ORDER BY ID DESC LIMIT 1") def insert_report_version(id, ver): sql = "DELETE FROM report_version WHERE report = %s;" dbhelper.execute_non_query(self.env.get_db_cnx(), sql, id) sql = """ INSERT INTO report_version (report, version) VALUES (%s, %s);""" # print "about to insert report_version" dbhelper.execute_non_query(self.env.get_db_cnx(), sql, id, ver) # print "inserted report_version" for report_group in all_reports: rlist = report_group["reports"] for report in rlist: title = report["title"] new_version = report["version"] report_id = [ rid for (rid, map_title) in self.reportmap if map_title == title ] if not report_id: bit = True sql = """INSERT INTO report (id,author,title,query,description) VALUES (%s,'Timing and Estimation Plugin',%s,%s,'') """ biggestId += 1 dbhelper.execute_non_query(self.env.get_db_cnx(), sql, biggestId, title, report["sql"]) insert_report_version(biggestId, new_version) report["reportnumber"] = biggestId self.reportmap.extend([(biggestId, title)]) else: report_id = report_id[0] report["reportnumber"] = report_id # If we had a report make sure its at the correct version if versions.has_key(title): (_, ver) = versions[title] else: ver = 0 if not ver: sql = """ UPDATE report SET query=%s WHERE id = %s """ print "updating report: %s" % title dbhelper.execute_non_query(self.env.get_db_cnx(), sql, report["sql"], report_id) insert_report_version(report_id, new_version) elif ver < new_version: sql = """ UPDATE report SET query=%s WHERE id = %s """ print "updating report to new version: %s" % title dbhelper.execute_non_query(self.env.get_db_cnx(), sql, report["sql"], report_id) sql = """ UPDATE report_version SET version = %s WHERE report = %s """ dbhelper.execute_non_query(self.env.get_db_cnx(), sql, new_version, report_id)