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 #517.

Closes #586

Signed-off-by: Leo von Klenze <[email protected]>
  • Loading branch information
lepokle committed Jul 22, 2019
1 parent a583a35 commit ee7b374
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
Empty file.
Empty file.
Empty file.
Empty file.
42 changes: 42 additions & 0 deletions scripts/migrations/012_migrate_todoid_to_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/python

# -----------------------------------------------------------------------------
# Copyright Siemens AG, 2019. 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.
# -----------------------------------------------------------------------------

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)

3 changes: 2 additions & 1 deletion scripts/migrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ To migrate it is recommended to do this in the following order:
### 2.2.0 -> 3.0.0
- `007_add_submitters_usergroup_to_moderation_request.py`
- `008_add_component_type_to_moderation_requests.py`
### 3.3.0 -> 3.4.0
### 3.3.0 -> 4.0.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 ee7b374

Please sign in to comment.