summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2016-08-19 13:36:43 -0300
committerdrebs <drebs@leap.se>2016-08-23 18:48:26 -0300
commit5f7395ebe9a8419de51c43ad189ca30af4b371f0 (patch)
tree578d713bb29b3854df02fa790486042b0af49178 /scripts
parent099f2b7453ee6486ccc23c0766f613709aacbde0 (diff)
[pkg] fail gracefully for missing design doc on couch schema migration script
Diffstat (limited to 'scripts')
-rw-r--r--scripts/migration/0.8.2/migrate_couch_schema/__init__.py18
1 files changed, 14 insertions, 4 deletions
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 d0dd41e3..456eadf0 100644
--- a/scripts/migration/0.8.2/migrate_couch_schema/__init__.py
+++ b/scripts/migration/0.8.2/migrate_couch_schema/__init__.py
@@ -6,6 +6,7 @@ Support functions for migration script.
import logging
from couchdb import Server
+from couchdb import ResourceNotFound
from leap.soledad.common.couch import GENERATION_KEY
from leap.soledad.common.couch import TRANSACTION_ID_KEY
@@ -38,7 +39,13 @@ def _is_migrateable(db):
def _get_transaction_log(db):
ddoc_path = ['_design', 'transactions', '_view', 'log']
resource = db.resource(*ddoc_path)
- _, _, data = resource.get_json()
+ try:
+ _, _, data = resource.get_json()
+ except ResourceNotFound:
+ logger.warning(
+ 'Missing transactions design document, '
+ 'can\'t get transaction log.')
+ return []
rows = data['rows']
transaction_log = []
gen = 1
@@ -152,6 +159,9 @@ def _delete_design_docs(db, do_migrate):
for ddoc in ['docs', 'syncs', 'transactions']:
doc_id = '_design/%s' % ddoc
doc = db.get(doc_id)
- logger.info("deleting design doc: %s" % doc_id)
- if do_migrate:
- db.delete(doc)
+ if doc:
+ logger.info("deleting design doc: %s" % doc_id)
+ if do_migrate:
+ db.delete(doc)
+ else:
+ logger.warning("design doc not found: %s" % doc_id)