Skip to content

Commit

Permalink
Merge branch 'hotfix/0.100.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria committed Nov 10, 2016
2 parents 19558dd + a156391 commit d897b9c
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions scripts/migration/migrate_osfstorageguidfile_trashedfilenodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import logging
import re
import sys

from framework.mongo import database
from website.app import init_app
from framework.transactions.context import TokuTransaction
from scripts import utils as script_utils

logger = logging.getLogger(__name__)


def get_targets():
guids = [
x['_id']
for x in database['guid'].find(
{'referent': 'osfstorageguidfile'},
{'_id': True}
)
]

paths = {
x['path'].strip('/'): x['_id']
for x in database['osfstorageguidfile'].find({
'_id': {'$in': guids},
'path': {'$not': re.compile('.*{{.*')}
}, {'path': True})
}
return paths, database['trashedfilenode'].find({'_id': {'$in': list(paths.keys())}})

def migrate():
paths, targets = get_targets()
for trashed in targets:
logger.info('Migrating {} => {}'.format(paths[trashed['_id']], trashed['_id']))
database['guid'].update(
{'_id': paths[trashed['_id']]},
{'$set': {
'referent': (trashed['_id'], 'trashedfilenode')
}}
)

def main():
dry_run = '--dry' in sys.argv
if not dry_run:
script_utils.add_file_logger(logger, __file__)
init_app(set_backends=True, routes=False)
with TokuTransaction():
migrate()
if dry_run:
raise RuntimeError('Dry Run -- Transaction rolled back')


if __name__ == '__main__':
main()

0 comments on commit d897b9c

Please sign in to comment.