From: Elrond Date: Wed, 14 Mar 2012 18:35:48 +0000 (+0100) Subject: Migration to move gps data around X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ca722c3caf8a7fdc7d8f82181c55228f9ba3c69b;p=mediagoblin.git Migration to move gps data around Move media_data["gps"]["*"] to media_data["gps_*"]. In preparation for media_data.gps_* --- diff --git a/mediagoblin/db/mongo/migrations.py b/mediagoblin/db/mongo/migrations.py index c5766b0d..23cf5e45 100644 --- a/mediagoblin/db/mongo/migrations.py +++ b/mediagoblin/db/mongo/migrations.py @@ -153,3 +153,21 @@ def convert_video_media_data(database): assert len(document['media_data']) == 1 document['media_data'] = document['media_data']['video'] collection.save(document) + +@RegisterMigration(11) +def convert_gps_media_data(database): + """ + Move media_data["gps"]["*"] to media_data["gps_*"]. + In preparation for media_data.gps_* + """ + collection = database['media_entries'] + target = collection.find( + {'media_data.gps': {'$exists': True}}) + + for document in target: + print document['_id'], "old:", document['media_data'] + for key, value in document['media_data']['gps'].iteritems(): + document['media_data']['gps_' + key] = value + del document['media_data']['gps'] + print document['_id'], "new:", document['media_data'] + collection.save(document)