From 8e87fecc4f9262ee290c0a148cdbfb214cc0417d Mon Sep 17 00:00:00 2001 From: drebs Date: Mon, 22 Aug 2016 20:56:49 -0300 Subject: [test] avoid failing on interrupted couch schema migrations --- .../migration/0.8.2/migrate_couch_schema/__init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'scripts/migration/0.8.2/migrate_couch_schema/__init__.py') diff --git a/scripts/migration/0.8.2/migrate_couch_schema/__init__.py b/scripts/migration/0.8.2/migrate_couch_schema/__init__.py index edf671ae..f0b456e4 100644 --- a/scripts/migration/0.8.2/migrate_couch_schema/__init__.py +++ b/scripts/migration/0.8.2/migrate_couch_schema/__init__.py @@ -32,9 +32,7 @@ def _get_couch_server(couch_url): def _is_migrateable(db): config_doc = db.get('u1db_config') - if config_doc is None: - return False - return True + return bool(config_doc) def _get_transaction_log(db): @@ -126,6 +124,8 @@ def _migrate_config_doc(db, do_migrate): logger.info("[%s] moving config doc: %s -> %s" % (db.name, old_doc['_id'], new_doc['_id'])) if do_migrate: + # the config doc must not exist, otherwise we would have skipped this + # database. db.save(new_doc) db.delete(old_doc) @@ -167,7 +167,16 @@ def _migrate_sync_docs(db, do_migrate): logger.debug("[%s] moving sync doc: %s -> %s" % (db.name, old_id, new_id)) if do_migrate: - db.save(new_doc) + try: + db.save(new_doc) + except ResourceConflict: + # this sync document already exists. if documents are the same, + # continue with migration. + existing_doc = db.get(new_id) + for key in [GENERATION_KEY, TRANSACTION_ID_KEY, + REPLICA_UID_KEY]: + if existing_doc[key] != new_doc[key]: + raise db.delete(old_doc) -- cgit v1.2.3