Merge branch 'master' into test_submission_views_365
[mediagoblin.git] / mediagoblin / db / migrations.py
CommitLineData
757f37a5
CAW
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
a01d04a0
CAW
17from mediagoblin.util import cleaned_markdown_conversion
18
757f37a5
CAW
19from mongokit import DocumentMigration
20
757f37a5
CAW
21
22class MediaEntryMigration(DocumentMigration):
23 def allmigration01_uploader_to_reference(self):
24 """
25 Old MediaEntry['uploader'] accidentally embedded the User instead
26 of referencing it. Fix that!
27 """
28 # uploader is an associative array
29 self.target = {'uploader': {'$type': 3}}
30 if not self.status:
31 for doc in self.collection.find(self.target):
32 self.update = {
33 '$set': {
34 'uploader': doc['uploader']['_id']}}
35 self.collection.update(
36 self.target, self.update, multi=True, safe=True)
37
a01d04a0
CAW
38 def allmigration02_add_description_html(self):
39 """
40 Now that we can have rich descriptions via Markdown, we should
41 update all existing entries to record the rich description versions.
42 """
a2c37d0a
CAW
43 self.target = {'description_html': {'$exists': False},
44 'description': {'$exists': True}}
a01d04a0
CAW
45
46 if not self.status:
47 for doc in self.collection.find(self.target):
48 self.update = {
49 '$set': {
50 'description_html': cleaned_markdown_conversion(
51 doc['description'])}}
52
e36ecab0 53class UserMigration(DocumentMigration):
54 def allmigration01_add_bio_and_url_profile(self):
55 """
56 User can elaborate profile with home page and biography
57 """
17bb7c38 58 self.target = {'url': {'$exists': False},
59 'bio': {'$exists': False}}
e36ecab0 60 if not self.status:
61 for doc in self.collection.find(self.target):
62 self.update = {
17bb7c38 63 '$set': {'url': '',
64 'bio': ''}}
e36ecab0 65 self.collection.update(
66 self.target, self.update, multi=True, safe=True)
67
68
17bb7c38 69MIGRATE_CLASSES = ['MediaEntry', 'User']