# HG changeset patch # User Daniele Nicolodi # Date 1319095833 -7200 # Node ID 495fb7bcf45a23615b984d3671d3ce16fb8ccdb8 # Parent 5e847f92a01063369594fc7e5bbf1ce9337ca85c Allow to force both current and destination schema version in upgrade operation. diff -r 5e847f92a010 -r 495fb7bcf45a src/ltpdarepo/admin.py --- a/src/ltpdarepo/admin.py Thu Oct 20 09:29:43 2011 +0200 +++ b/src/ltpdarepo/admin.py Thu Oct 20 09:30:33 2011 +0200 @@ -88,7 +88,8 @@ from .upgrade import upgrade cmd = commands.add(upgrade) -cmd.add_argument('--from', type=float, dest='force', metavar='REV') +cmd.add_argument('--from', type=float, dest='_from', metavar='REV') +cmd.add_argument('--to', type=float, dest='_to', metavar='REV') def useradd(username, password=None, **kwargs): diff -r 5e847f92a010 -r 495fb7bcf45a src/ltpdarepo/upgrade.py --- a/src/ltpdarepo/upgrade.py Thu Oct 20 09:29:43 2011 +0200 +++ b/src/ltpdarepo/upgrade.py Thu Oct 20 09:30:33 2011 +0200 @@ -18,7 +18,7 @@ return func -def upgrade(force=None): +def upgrade(_from=None, _to=None): """run database schema upgrade steps""" logger = logging.getLogger(__name__) @@ -27,19 +27,25 @@ # current schema version curs.execute("""SELECT value+0 FROM options WHERE name='version'""") - current = curs.fetchone()[0] - logger.info("current database shema v%s", current) + curr = curs.fetchone()[0] + logger.info("current database shema v%s", curr) # allow to force upgrade from specific version - if force is not None: - current = force - logger.info("force upgrade from schema v%s", current) + if _from is not None: + curr = _from + logger.info("force upgrade from schema v%s", curr) - while current != SCHEMA: + # allow to force upgrade to specific version + dest = SCHEMA + if _to is not None: + dest = _to + logger.info("force upgrade to schema v%s", dest) + + while curr < dest: # next upgrade step - step = steps.get(current, None) + step = steps.get(curr, None) if step is None: - raise ValueError("no upgrade path from database shema v%s" % current) + raise ValueError("no upgrade path from database shema v%s" % curr) fromr, tor, func = step # run upgrade step @@ -47,9 +53,9 @@ func(conn) # update current schema version - current = tor + curr = tor curs.execute("""UPDATE options SET value=%s - WHERE name='version'""", str(current)) + WHERE name='version'""", str(curr)) conn.commit() conn.close()