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
.util
import cleaned_markdown_conversion
18 # from mediagoblin.db.util import RegisterMigration
20 from mongokit
import DocumentMigration
23 # This is where the first new-style migration will be written!
25 # Please see mediagoblin/tests/test_migrations.py for some examples of
28 # @RegisterMigration(1)
29 # def do_something(database):
33 class MediaEntryMigration(DocumentMigration
):
34 def allmigration01_uploader_to_reference(self
):
36 Old MediaEntry['uploader'] accidentally embedded the User instead
37 of referencing it. Fix that!
39 # uploader is an associative array
40 self
.target
= {'uploader': {'$type': 3}}
42 for doc
in self
.collection
.find(self
.target
):
45 'uploader': doc
['uploader']['_id']}}
46 self
.collection
.update(
47 self
.target
, self
.update
, multi
=True, safe
=True)
49 def allmigration02_add_description_html(self
):
51 Now that we can have rich descriptions via Markdown, we should
52 update all existing entries to record the rich description versions.
54 self
.target
= {'description_html': {'$exists': False},
55 'description': {'$exists': True}}
58 for doc
in self
.collection
.find(self
.target
):
61 'description_html': cleaned_markdown_conversion(
64 class UserMigration(DocumentMigration
):
65 def allmigration01_add_bio_and_url_profile(self
):
67 User can elaborate profile with home page and biography
69 self
.target
= {'url': {'$exists': False},
70 'bio': {'$exists': False}}
72 for doc
in self
.collection
.find(self
.target
):
76 self
.collection
.update(
77 self
.target
, self
.update
, multi
=True, safe
=True)
80 MIGRATE_CLASSES
= ['MediaEntry', 'User']