X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fupdate_db.py;h=61a1089210295e5ab759d7858e59edc5f4bfb58e;hb=5a61a05250b1bf5d54661103e8999eb7c7fc9207;hp=6f162cbfff98447b05e2fea8bf9976f696be1991;hpb=8da2a8dd940bf5f7c381c887c1c2fadd6457f5f4;p=dak.git diff --git a/dak/update_db.py b/dak/update_db.py index 6f162cbf..61a10892 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -121,6 +121,7 @@ Updates dak's database schema to the lastest version. You should disable crontab print "Determining dak database revision ..." cnf = Config() logger = Logger('update-db') + modules = [] try: # Build a connect string @@ -157,13 +158,20 @@ Updates dak's database schema to the lastest version. You should disable crontab database_revision = 0 dbfiles = glob(os.path.join(os.path.dirname(__file__), 'dakdb/update*.py')) - required_database_schema = int(max(findall('update(\d+).py', " ".join(dbfiles)))) + required_database_schema = max(map(int, findall('update(\d+).py', " ".join(dbfiles)))) print "dak database schema at %d" % database_revision print "dak version requires schema %d" % required_database_schema if database_revision < required_database_schema: - prompt = "Update database? (y/N) " + print "\nUpdates to be applied:" + for i in range(database_revision, required_database_schema): + i += 1 + dakdb = __import__("dakdb", globals(), locals(), ['update'+str(i)]) + update_module = getattr(dakdb, "update"+str(i)) + print "Update %d: %s" % (i, next(s for s in update_module.__doc__.split("\n") if s)) + modules.append((update_module, i)) + prompt = "\nUpdate database? (y/N) " answer = utils.our_raw_input(prompt) if answer.upper() != 'Y': sys.exit(0) @@ -172,17 +180,16 @@ Updates dak's database schema to the lastest version. You should disable crontab logger.log(["no updates required"]) sys.exit(0) - for i in range (database_revision, required_database_schema): + for module in modules: + (update_module, i) = module try: - dakdb = __import__("dakdb", globals(), locals(), ['update'+str(i+1)]) - update_module = getattr(dakdb, "update"+str(i+1)) update_module.do_update(self) - message = "updated database schema from %d to %d" % (database_revision, i+1) + message = "updated database schema from %d to %d" % (database_revision, i) print message logger.log([message]) except DBUpdateError as e: # Seems the update did not work. - print "Was unable to update database schema from %d to %d." % (database_revision, i+1) + print "Was unable to update database schema from %d to %d." % (database_revision, i) print "The error message received was %s" % (e) logger.log(["DB Schema upgrade failed"]) logger.close()