1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from mediagoblin
.db
.util
import RegisterMigration
18 from mediagoblin
.util
import cleaned_markdown_conversion
21 # Please see mediagoblin/tests/test_migrations.py for some examples of
26 def user_add_bio_html(database
):
28 Users now have richtext bios via Markdown, reflect appropriately.
30 collection
= database
['users']
32 target
= collection
.find(
33 {'bio_html': {'$exists': False}})
35 for document
in target
:
36 document
['bio_html'] = cleaned_markdown_conversion(
38 collection
.save(document
)
42 def mediaentry_mediafiles_main_to_original(database
):
44 Rename "main" media file to "original".
46 collection
= database
['media_entries']
47 target
= collection
.find(
48 {'media_files.main': {'$exists': True}})
50 for document
in target
:
51 original
= document
['media_files'].pop('main')
52 document
['media_files']['original'] = original
54 collection
.save(document
)
58 def mediaentry_remove_thumbnail_file(database
):
60 Use media_files['thumb'] instead of media_entries['thumbnail_file']
62 database
['media_entries'].update(
63 {'thumbnail_file': {'$exists': True}},
64 {'$unset': {'thumbnail_file': 1}},
69 def mediaentry_add_queued_task_id(database
):
71 Add the 'queued_task_id' field for entries that don't have it.
73 collection
= database
['media_entries']
75 {'queued_task_id': {'$exists': False}},
76 {'$set': {'queued_task_id': None}},
81 def mediaentry_add_fail_error_and_metadata(database
):
83 Add 'fail_error' and 'fail_metadata' fields to media entries
85 collection
= database
['media_entries']
87 {'fail_error': {'$exists': False}},
88 {'$set': {'fail_error': None}},
92 {'fail_metadata': {'$exists': False}},
93 {'$set': {'fail_metadata': {}}},