|
a/Allura/allura/migrations.py |
|
b/Allura/allura/migrations.py |
|
... |
|
... |
14 |
from forgehg import model as HgM
|
14 |
from forgehg import model as HgM
|
15 |
from forgesvn import model as SVNM
|
15 |
from forgesvn import model as SVNM
|
16 |
|
16 |
|
17 |
STATS_COLLECTION_SIZE=100000
|
17 |
STATS_COLLECTION_SIZE=100000
|
18 |
|
18 |
|
19 |
class MigrateFiles(Migration):
|
19 |
class MigrateProjectsAndFiles(Migration):
|
20 |
version = 14
|
20 |
version = 14
|
21 |
|
21 |
|
22 |
def up(self):
|
22 |
def up(self):
|
|
|
23 |
self._up_projects()
|
23 |
db = self.session.db
|
24 |
db = self.session.db
|
24 |
for collection in db.collection_names():
|
25 |
for collection in db.collection_names():
|
25 |
if collection.endswith('.files'):
|
26 |
if collection.endswith('.files'):
|
26 |
self.up_collection(db, collection)
|
27 |
self._up_collection(db, collection)
|
27 |
|
28 |
|
28 |
def down(self):
|
29 |
def down(self):
|
29 |
# Nothing to do, really, as long as we don't update
|
30 |
# Nothing to do, really, as long as we don't update
|
30 |
# any metadata while upgraded
|
31 |
# any metadata while upgraded
|
31 |
pass
|
32 |
pass
|
|
|
33 |
|
|
|
34 |
def _up_projects(self):
|
|
|
35 |
projects = self.session.db.project
|
|
|
36 |
for p in projects.find():
|
|
|
37 |
if p.get('database_uri').startswith('mongo://'):
|
|
|
38 |
p['database_uri'] = p['database_uri'].replace('mongo://', 'mongodb://')
|
|
|
39 |
projects.save(p)
|
32 |
|
40 |
|
33 |
def _up_collection(self, db, collection_name):
|
41 |
def _up_collection(self, db, collection_name):
|
34 |
collection = db[collection_name]
|
42 |
collection = db[collection_name]
|
35 |
# First, create a 'root' collection, clearing it out as well
|
43 |
# First, create a 'root' collection, clearing it out as well
|
36 |
root_collection = db[collection_name.split('.')[0]]
|
44 |
root_collection = db[collection_name.split('.')[0]]
|
|
... |
|
... |
38 |
for doc in collection.find():
|
46 |
for doc in collection.find():
|
39 |
newdoc = dict(doc)
|
47 |
newdoc = dict(doc)
|
40 |
newdoc.update(doc['metadata'])
|
48 |
newdoc.update(doc['metadata'])
|
41 |
newdoc.pop('metadata')
|
49 |
newdoc.pop('metadata')
|
42 |
newdoc['file_id'] = doc['_id']
|
50 |
newdoc['file_id'] = doc['_id']
|
43 |
for aid_name in ('post_id', 'page_id', 'post_id', 'ticket_id'):
|
51 |
for aid_name in ('page_id', 'ticket_id'):
|
44 |
if aid_name in newdoc:
|
52 |
if aid_name in newdoc:
|
45 |
newdoc['artifact_id'] = newdoc.pop(aid_name)
|
53 |
newdoc['artifact_id'] = newdoc.pop(aid_name)
|
|
|
54 |
if 'post_id' in newdoc:
|
|
|
55 |
# post_id is stored along with artifact_id in posts
|
|
|
56 |
newdoc['artifact_id'] = newdoc['post_id']
|
46 |
root_collection.save(newdoc)
|
57 |
root_collection.save(newdoc)
|
47 |
|
58 |
|
48 |
class CreateStatsCollection(Migration):
|
59 |
class CreateStatsCollection(Migration):
|
49 |
version = 13
|
60 |
version = 13
|
50 |
|
61 |
|