Merge remote-tracking branch 'refs/remotes/upstream/master' into 569-application...
[mediagoblin.git] / mediagoblin / db / migrations.py
CommitLineData
757f37a5 1# GNU MediaGoblin -- federated, autonomous media hosting
12a100e4 2# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
757f37a5
CAW
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
c2ddd85e 17from mediagoblin.db.util import RegisterMigration
5ebe69e5
CAW
18from mediagoblin.util import cleaned_markdown_conversion
19
a01d04a0 20
0c915735
CAW
21# Please see mediagoblin/tests/test_migrations.py for some examples of
22# basic migrations.
23
5ebe69e5
CAW
24
25@RegisterMigration(1)
26def 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)
fa92d52f
CAW
39
40
41@RegisterMigration(2)
42def 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)
6b9ee0ca
CAW
55
56
57@RegisterMigration(3)
84abd2bb
CFD
58def mediaentry_remove_thumbnail_file(database):
59 """
60 Use media_files['thumb'] instead of media_entries['thumbnail_file']
61 """
62 database['media_entries'].update(
63 {'thumbnail_file': {'$exists': True}},
64 {'$unset': {'thumbnail_file': 1}},
fabdccd0 65 multi=True)
ba4858c5
CAW
66
67
68@RegisterMigration(4)
6b9ee0ca
CAW
69def mediaentry_add_queued_task_id(database):
70 """
71 Add the 'queued_task_id' field for entries that don't have it.
72 """
73 collection = database['media_entries']
74 collection.update(
75 {'queued_task_id': {'$exists': False}},
76 {'$set': {'queued_task_id': None}},
77 multi=True)
6c50c210
CAW
78
79
80@RegisterMigration(5)
81def mediaentry_add_fail_error_and_metadata(database):
82 """
83 Add 'fail_error' and 'fail_metadata' fields to media entries
84 """
85 collection = database['media_entries']
86 collection.update(
87 {'fail_error': {'$exists': False}},
88 {'$set': {'fail_error': None}},
89 multi=True)
90
91 collection.update(
92 {'fail_metadata': {'$exists': False}},
93 {'$set': {'fail_metadata': {}}},
94 multi=True)
25ba955e
AV
95
96
97@RegisterMigration(6)
98def user_add_forgot_password_token_and_expires(database):
99 """
100 Add token and expiration fields to help recover forgotten passwords
101 """
102 database['users'].update(
65030735 103 {'fp_verification_key': {'$exists': False}},
2db31581 104 {'$set': {'fp_verification_key': None}},
25ba955e
AV
105 multi=True)
106 database['users'].update(
107 {'fp_token_expire': {'$exists': False}},
2db31581 108 {'$set': {'fp_token_expire': None}},
25ba955e 109 multi=True)