Migration for mediafiles main->original
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 17 Jul 2011 13:50:09 +0000 (08:50 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 17 Jul 2011 13:50:09 +0000 (08:50 -0500)
mediagoblin/db/migrations.py

index f398f4b34c8b5f899b02f232caa7d4a75abe38bc..6a8ebcf920d49ee1f64a722f7ca6184bf1af9781 100644 (file)
@@ -36,3 +36,19 @@ def user_add_bio_html(database):
         document['bio_html'] = cleaned_markdown_conversion(
             document['bio'])
         collection.save(document)
+
+
+@RegisterMigration(2)
+def mediaentry_mediafiles_main_to_original(database):
+    """
+    Rename "main" media file to "original".
+    """
+    collection = database['media_entries']
+    target = collection.find(
+        {'media_files.main': {'$exists': True}})
+
+    for document in target:
+        original = document['media_files'].pop('main')
+        document['media_files']['original'] = original
+
+        collection.save(document)