Skip to content
Snippets Groups Projects
Commit 4ed6bb54 authored by drebs's avatar drebs
Browse files

[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.
parent 46bb2b65
Branches
No related tags found
No related merge requests found
...@@ -119,6 +119,21 @@ def _migrate_sync_docs(db, do_migrate): ...@@ -119,6 +119,21 @@ def _migrate_sync_docs(db, do_migrate):
for row in view.rows: for row in view.rows:
old_doc = row['doc'] old_doc = row['doc']
old_id = old_doc['_id'] 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_', '') replica_uid = old_id.replace('u1db_sync_', '')
new_id = "%s%s" % (SYNC_DOC_ID_PREFIX, replica_uid) new_id = "%s%s" % (SYNC_DOC_ID_PREFIX, replica_uid)
new_doc = { new_doc = {
......
...@@ -31,7 +31,11 @@ initial_docs = [ ...@@ -31,7 +31,11 @@ initial_docs = [
{'_id': 'doc2', 'u1db_transactions': [(2, 'trans-2'), (4, 'trans-4')]}, {'_id': 'doc2', 'u1db_transactions': [(2, 'trans-2'), (4, 'trans-4')]},
{'_id': '_design/docs'}, {'_id': '_design/docs'},
{'_id': '_design/syncs'}, {'_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'},
] ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment