From: Elrond Date: Thu, 22 Mar 2012 19:59:28 +0000 (+0100) Subject: Create migration to move exif data around in media_data. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c8c75ad04475c2ced5b70dac51a6bcd33c8a0465;p=mediagoblin.git Create migration to move exif data around in media_data. Move media_data['exif']['clean'] to media_data['exif_all'] drop media_data['exif']['useful'] drop media_data['exif'] --- diff --git a/mediagoblin/db/mongo/migrations.py b/mediagoblin/db/mongo/migrations.py index 1d33460e..2685078f 100644 --- a/mediagoblin/db/mongo/migrations.py +++ b/mediagoblin/db/mongo/migrations.py @@ -119,6 +119,7 @@ def media_type_image_to_multimedia_type_image(database): {'$set': {'media_type': 'mediagoblin.media_types.image'}}, multi=True) + @RegisterMigration(8) def mediaentry_add_license(database): """ @@ -140,6 +141,7 @@ def remove_calculated_html(database): drop_table_field(database, 'media_entries', 'description_html') drop_table_field(database, 'media_comments', 'content_html') + @RegisterMigration(10) def convert_video_media_data(database): """ @@ -154,6 +156,7 @@ def convert_video_media_data(database): document['media_data'] = document['media_data']['video'] collection.save(document) + @RegisterMigration(11) def convert_gps_media_data(database): """ @@ -169,3 +172,25 @@ def convert_gps_media_data(database): document['media_data']['gps_' + key] = value del document['media_data']['gps'] collection.save(document) + + +@RegisterMigration(12) +def convert_exif_media_data(database): + """ + Move media_data["exif"]["clean"] to media_data["exif_all"]. + Drop media_data["exif"]["useful"] + In preparation for media_data.exif_all + """ + collection = database['media_entries'] + target = collection.find( + {'media_data.exif.clean': {'$exists': True}}) + + for document in target: + media_data = document['media_data'] + print "old:", document['_id'], media_data + media_data['exif_all'] = media_data['exif'].pop('clean') + del media_data['exif']['useful'] + assert len(media_data['exif']) == 0 + del media_data['exif'] + print "new:", document['_id'], media_data + collection.save(document)