Merge remote branch 'remotes/elrond/dev/init'
[mediagoblin.git] / mediagoblin / db / migrations.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
3 #
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.
8 #
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.
13 #
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/>.
16
17 from mediagoblin.db.util import RegisterMigration
18 from mediagoblin.util import cleaned_markdown_conversion
19
20
21 # Please see mediagoblin/tests/test_migrations.py for some examples of
22 # basic migrations.
23
24
25 @RegisterMigration(1)
26 def user_add_bio_html(database):
27 """
28 Users now have richtext bios via Markdown, reflect appropriately.
29 """
30 collection = database['users']
31
32 target = collection.find(
33 {'bio_html': {'$exists': False}})
34
35 for document in target:
36 document['bio_html'] = cleaned_markdown_conversion(
37 document['bio'])
38 collection.save(document)
39
40
41 @RegisterMigration(2)
42 def mediaentry_mediafiles_main_to_original(database):
43 """
44 Rename "main" media file to "original".
45 """
46 collection = database['media_entries']
47 target = collection.find(
48 {'media_files.main': {'$exists': True}})
49
50 for document in target:
51 original = document['media_files'].pop('main')
52 document['media_files']['original'] = original
53
54 collection.save(document)