Mercurial > hg > ltpdarepo
changeset 237:16f095c74706
Make collections upgrade step more robust.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 12 Dec 2011 16:11:47 +0100 |
parents | 39b50b763f11 |
children | 3fee7db86a99 863e3e81498c |
files | src/ltpdarepo/upgrade.py |
diffstat | 1 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ltpdarepo/upgrade.py Mon Dec 12 15:10:28 2011 +0100 +++ b/src/ltpdarepo/upgrade.py Mon Dec 12 16:11:47 2011 +0100 @@ -504,15 +504,19 @@ for id, nobjs, obj_ids in curs.fetchall(): ids = map(int, obj_ids.split(',')) if len(ids) != nobjs: - logger.warning(" bad collection description cid=%d", id) + logger.warning(" bad collection description %d", id) # discard collections composed by a single object if len(ids) == 1: - logger.info(" deleting single object collection cid=%d", id) + logger.info(" deleting single object collection %d", id) curs.execute("""DELETE FROM collections WHERE id=%s""", id) continue for obj_id in ids: - curs.execute("""INSERT INTO collections2objs (id, obj_id) - VALUES (%s, %s)""", (id, obj_id)) + try: + curs.execute("""INSERT INTO collections2objs (id, obj_id) + VALUES (%s, %s)""", (id, obj_id)) + except mysql.IntegrityError: + logger.warning(" ignoring non existent object %d " + "in collection %d", obj_id, id) # drop old columns curs.execute("""ALTER TABLE collections DROP COLUMN nobjs""")