@@ -0,0 +1,1319 @@
+import sys%0Aimport logging%0Afrom modularodm import Q%0A%0Afrom website.app import init_app%0Afrom website.files.models import FileVersion%0A%0Afrom scripts import utils as script_utils%0A%0Afrom framework.transactions.context import TokuTransaction%0A%0A%0Alogger = logging.getLogger(__name__)%0A%0A%0Adef do_migration():%0A    logger.info('Starting sha256 recovery migration')%0A    for version in FileVersion.find(Q('metadata.sha256', 'eq', None)):%0A        if not version.location:%0A            continue%0A        logger.debug('Adding sha %7B%7D to version %7B%7D'.format(version.location%5B'object'%5D, version._id))%0A        version.metadata%5B'sha256'%5D = version.location%5B'object'%5D%0A        version.save()%0A%0Adef main(dry=True):%0A    init_app(set_backends=True, routes=False)  # Sets the storage backends on all models%0A%0A    with TokuTransaction():%0A        do_migration()%0A        if dry:%0A            raise Exception('Abort Transaction - Dry Run')%0A%0A%0Aif __name__ == '__main__':%0A    dry = 'dry' in sys.argv%0A    if not dry:%0A        script_utils.add_file_logger(logger, __file__)%0A    if 'debug' in sys.argv:%0A        logger.setLevel(logging.DEBUG)%0A    elif 'warning' in sys.argv:%0A        logger.setLevel(logging.WARNING)%0A    elif 'info' in sys.argv:%0A        logger.setLevel(logging.INFO)%0A    elif 'error' in sys.argv:%0A        logger.setLevel(logging.ERROR)%0A    main(dry=dry)%0A

Add a migration for repopulating sha256s of older osfstorage file versions