aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/db')
-rw-r--r--mediagoblin/db/migrations.py39
-rw-r--r--mediagoblin/db/models.py6
2 files changed, 44 insertions, 1 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py
new file mode 100644
index 00000000..d035b15b
--- /dev/null
+++ b/mediagoblin/db/migrations.py
@@ -0,0 +1,39 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011 Free Software Foundation, Inc
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from mongokit import DocumentMigration
+
+from mediagoblin import globals as mediagoblin_globals
+
+
+class MediaEntryMigration(DocumentMigration):
+ def allmigration01_uploader_to_reference(self):
+ """
+ Old MediaEntry['uploader'] accidentally embedded the User instead
+ of referencing it. Fix that!
+ """
+ # uploader is an associative array
+ self.target = {'uploader': {'$type': 3}}
+ if not self.status:
+ for doc in self.collection.find(self.target):
+ self.update = {
+ '$set': {
+ 'uploader': doc['uploader']['_id']}}
+ self.collection.update(
+ self.target, self.update, multi=True, safe=True)
+
+
+MIGRATE_CLASSES = ['MediaEntry']
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index 8e7889eb..3fc8d9e8 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -21,6 +21,8 @@ from mongokit import Document, Set
from mediagoblin import util
from mediagoblin.auth import lib as auth_lib
from mediagoblin import globals as mediagoblin_globals
+from mediagoblin.db import migrations
+from mediagoblin.db.util import ObjectId
###################
# Custom validators
@@ -67,7 +69,7 @@ class MediaEntry(Document):
__collection__ = 'media_entries'
structure = {
- 'uploader': User,
+ 'uploader': ObjectId,
'title': unicode,
'slug': unicode,
'created': datetime.datetime,
@@ -99,6 +101,8 @@ class MediaEntry(Document):
'created': datetime.datetime.utcnow,
'state': u'unprocessed'}
+ migration_handler = migrations.MediaEntryMigration
+
# Actually we should referene uniqueness by uploader, but we
# should fix http://bugs.foocorp.net/issues/340 first.
# indexes = [