1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
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
.tools
.text
import cleaned_markdown_conversion
21 def add_table_field(db
, table_name
, field_name
, default_value
):
23 Add a new field to the table/collection named table_name.
24 The field will have the name field_name and the value default_value
26 db
[table_name
].update(
27 {field_name
: {'$exists': False}},
28 {'$set': {field_name
: default_value
}},
32 # Please see mediagoblin/tests/test_migrations.py for some examples of
37 def user_add_bio_html(database
):
39 Users now have richtext bios via Markdown, reflect appropriately.
41 collection
= database
['users']
43 target
= collection
.find(
44 {'bio_html': {'$exists': False}})
46 for document
in target
:
47 document
['bio_html'] = cleaned_markdown_conversion(
49 collection
.save(document
)
53 def mediaentry_mediafiles_main_to_original(database
):
55 Rename "main" media file to "original".
57 collection
= database
['media_entries']
58 target
= collection
.find(
59 {'media_files.main': {'$exists': True}})
61 for document
in target
:
62 original
= document
['media_files'].pop('main')
63 document
['media_files']['original'] = original
65 collection
.save(document
)
69 def mediaentry_remove_thumbnail_file(database
):
71 Use media_files['thumb'] instead of media_entries['thumbnail_file']
73 database
['media_entries'].update(
74 {'thumbnail_file': {'$exists': True}},
75 {'$unset': {'thumbnail_file': 1}},
80 def mediaentry_add_queued_task_id(database
):
82 Add the 'queued_task_id' field for entries that don't have it.
84 add_table_field(database
, 'media_entries', 'queued_task_id', None)
88 def mediaentry_add_fail_error_and_metadata(database
):
90 Add 'fail_error' and 'fail_metadata' fields to media entries
92 add_table_field(database
, 'media_entries', 'fail_error', None)
93 add_table_field(database
, 'media_entries', 'fail_metadata', {})
97 def user_add_forgot_password_token_and_expires(database
):
99 Add token and expiration fields to help recover forgotten passwords
101 add_table_field(database
, 'users', 'fp_verification_key', None)
102 add_table_field(database
, 'users', 'fp_token_expire', None)
105 @RegisterMigration(7)
106 def media_type_image_to_multimedia_type_image(database
):
107 database
['media_entries'].update(
108 {'media_type': 'image'},
109 {'$set': {'media_type': 'mediagoblin.media_types.image'}},