Skip to content

Commit

Permalink
feat(todoMigration): migration script for todos
Browse files Browse the repository at this point in the history
This commits add a migration script for changing the 'todoId' into
the 'title' for todo documents.

This is necessary due to the changes in eclipse-sw360#517.

Closes eclipse-sw360#586

Signed-off-by: Leo von Klenze <[email protected]>
  • Loading branch information
lepokle committed Jul 19, 2019
1 parent a583a35 commit c63d656
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
Empty file.
Empty file.
Empty file.
Empty file.
44 changes: 44 additions & 0 deletions scripts/migrations/012_migrate_todoid_to_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/python
# -----------------------------------------------------------------------------
# Copyright Siemens AG, 2016. Part of the SW360 Portal Project.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# This is a manual database migration script. It is assumed that a
# dedicated framework for automatic migration will be written in the
# future. When that happens, this script should be refactored to conform
# to the framework's prerequisites to be run by the framework. For
# example, server address and db name should be parametrized, the code
# reorganized into a single class or function, etc.
#
# initial author: [email protected]
#
# -----------------------------------------------------------------------------

import couchdb

COUCHSERVER = "http://localhost:5984/"
DBNAME = 'sw360db'

couch=couchdb.Server(COUCHSERVER)
db = couch[DBNAME]

todos_by_id_fun = '''function(doc){
if (doc.type=="todo"){
emit(doc._id, doc)
}
}'''

todos = db.query(todos_by_id_fun)


print 'Updating todos and replace todoId with title'
for todo_row in todos:
todo = todo_row.value
todo['title'] = str(todo['todoId'])
del todo['todoId']
db.save(todo)

1 change: 1 addition & 0 deletions scripts/migrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ To migrate it is recommended to do this in the following order:
- `008_add_component_type_to_moderation_requests.py`
### 3.3.0 -> 3.4.0
- `011_migrate_attachment_usages_license_info.py`
- `012_migrate_todoid_to_title.py`

## Optional usage
- `009_overwrite_release_name_with_component_name.py`
Expand Down

0 comments on commit c63d656

Please sign in to comment.