summaryrefslogtreecommitdiff
path: root/scripts/migration
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2016-08-19 12:14:40 -0300
committerdrebs <drebs@leap.se>2016-08-23 18:48:26 -0300
commit4ed6bb54f1cc96ee0a8b98914c98b94edc1d1b1c (patch)
tree056a51d85176ca06623f68c9c20e13b04241f99e /scripts/migration
parent46bb2b65e6fe642b07dee1de6c628c6f2cd303fd (diff)
[pkg] add leftovers deletion to couch scehma migration script
Previous versions of the couchdb schema used documents "u1db_sync_log" and "u1db_sync_state" to store sync metadata. At some point this was changed, but the documents might have stayed as leftovers. This commit adds the deletion of such documents to the migration script.
Diffstat (limited to 'scripts/migration')
-rw-r--r--scripts/migration/0.8.2/migrate_couch_schema/__init__.py15
-rw-r--r--scripts/migration/0.8.2/tests/conftest.py6
2 files changed, 20 insertions, 1 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 37e5a525..60214aae 100644
--- a/scripts/migration/0.8.2/migrate_couch_schema/__init__.py
+++ b/scripts/migration/0.8.2/migrate_couch_schema/__init__.py
@@ -119,6 +119,21 @@ def _migrate_sync_docs(db, do_migrate):
for row in view.rows:
old_doc = row['doc']
old_id = old_doc['_id']
+
+ # older schemas used different documents with ids starting with
+ # "u1db_sync" to store sync-related data:
+ #
+ # - u1db_sync_log: was used to store the whole sync log.
+ # - u1db_sync_state: was used to store the sync state.
+ #
+ # if any of these documents exist in the current db, they are leftover
+ # from previous migrations, and should just be removed.
+ if old_id in ['u1db_sync_log', 'u1db_sync_state']:
+ logger.info('removing leftover "u1db_sync_log" document...')
+ if do_migrate:
+ db.delete(old_doc)
+ continue
+
replica_uid = old_id.replace('u1db_sync_', '')
new_id = "%s%s" % (SYNC_DOC_ID_PREFIX, replica_uid)
new_doc = {
diff --git a/scripts/migration/0.8.2/tests/conftest.py b/scripts/migration/0.8.2/tests/conftest.py
index 92d1e17e..8e49891c 100644
--- a/scripts/migration/0.8.2/tests/conftest.py
+++ b/scripts/migration/0.8.2/tests/conftest.py
@@ -31,7 +31,11 @@ initial_docs = [
{'_id': 'doc2', 'u1db_transactions': [(2, 'trans-2'), (4, 'trans-4')]},
{'_id': '_design/docs'},
{'_id': '_design/syncs'},
- {'_id': '_design/transactions', 'views': {'log': {'map': transaction_map}}}
+ {'_id': '_design/transactions',
+ 'views': {'log': {'map': transaction_map}}},
+ # the following should be removed if found in the dbs
+ {'_id': 'u1db_sync_log'},
+ {'_id': 'u1db_sync_state'},
]