From c63d656462c8c1c9603bd40f4ea44535a401df21 Mon Sep 17 00:00:00 2001 From: Leo von Klenze Date: Fri, 19 Jul 2019 07:49:41 +0200 Subject: [PATCH] feat(todoMigration): migration script for todos 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 --- ...mitters_usergroup_to_moderation_request.py | 0 ...d_component_type_to_moderation_requests.py | 0 ...rwrite_release_name_with_component_name.py | 0 ...pair_missing_vendorId_links_in_releases.py | 0 .../migrations/012_migrate_todoid_to_title.py | 44 +++++++++++++++++++ scripts/migrations/README.md | 1 + 6 files changed, 45 insertions(+) mode change 100644 => 100755 scripts/migrations/007_add_submitters_usergroup_to_moderation_request.py mode change 100644 => 100755 scripts/migrations/008_add_component_type_to_moderation_requests.py mode change 100644 => 100755 scripts/migrations/009_overwrite_release_name_with_component_name.py mode change 100644 => 100755 scripts/migrations/010_repair_missing_vendorId_links_in_releases.py create mode 100755 scripts/migrations/012_migrate_todoid_to_title.py diff --git a/scripts/migrations/007_add_submitters_usergroup_to_moderation_request.py b/scripts/migrations/007_add_submitters_usergroup_to_moderation_request.py old mode 100644 new mode 100755 diff --git a/scripts/migrations/008_add_component_type_to_moderation_requests.py b/scripts/migrations/008_add_component_type_to_moderation_requests.py old mode 100644 new mode 100755 diff --git a/scripts/migrations/009_overwrite_release_name_with_component_name.py b/scripts/migrations/009_overwrite_release_name_with_component_name.py old mode 100644 new mode 100755 diff --git a/scripts/migrations/010_repair_missing_vendorId_links_in_releases.py b/scripts/migrations/010_repair_missing_vendorId_links_in_releases.py old mode 100644 new mode 100755 diff --git a/scripts/migrations/012_migrate_todoid_to_title.py b/scripts/migrations/012_migrate_todoid_to_title.py new file mode 100755 index 0000000000..25c6d80e42 --- /dev/null +++ b/scripts/migrations/012_migrate_todoid_to_title.py @@ -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: alex.borodin@evosoft.com +# +# ----------------------------------------------------------------------------- + +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) + diff --git a/scripts/migrations/README.md b/scripts/migrations/README.md index 1870bb5f9a..0c8b5759f8 100644 --- a/scripts/migrations/README.md +++ b/scripts/migrations/README.md @@ -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`