Migration to move gps data around
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 14 Mar 2012 18:35:48 +0000 (19:35 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 14 Mar 2012 19:17:49 +0000 (20:17 +0100)
Move media_data["gps"]["*"] to media_data["gps_*"].
In preparation for media_data.gps_*

mediagoblin/db/mongo/migrations.py

index c5766b0d8687e4d25ff114e692c01809d233d8d8..23cf5e45fb0ae937c0c20b91dda9e1522151fafa 100644 (file)
@@ -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)