User migration works (but the rest of the system isn't updated for new user setup yet)

This commit is contained in:
Christopher Allan Webber
2011-05-22 10:52:53 -05:00
parent 8820121ad1
commit 757f37a52d
4 changed files with 93 additions and 1 deletions

View File

@@ -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']

View File

@@ -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 = [