Create migration to move exif data around in media_data.
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Thu, 22 Mar 2012 19:59:28 +0000 (20:59 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 25 Mar 2012 12:42:03 +0000 (14:42 +0200)
Move media_data['exif']['clean'] to media_data['exif_all']
drop media_data['exif']['useful']
drop media_data['exif']

mediagoblin/db/mongo/migrations.py

index 1d33460ea00ad15e72e7b033da09934b02217e9f..2685078fcff72a601cca9b318ac23767814b43a2 100644 (file)
@@ -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)