Download this file

migrate_project_roles.py    28 lines (22 with data), 715 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'''Merge all the OldProjectRole collections in various project databases into a
central ProjectRole collection.
'''
import logging
from pylons import c
from ming.orm import session, state
from allura import model as M
log = logging.getLogger(__name__)
seen_databases = set()
projects = M.Project.query.find().all()
for p in projects:
if p.database_uri in seen_databases:
continue
seen_databases.add(p.database_uri)
log.info('Moving project roles in database %s to main DB',
p.database_uri)
c.project = p
for opr in M.OldProjectRole.query.find():
pr = M.ProjectRole(**state(opr).document)
session(opr).clear()
session(pr).flush()
session(pr).clear()