Skip to content
Snippets Groups Projects
Commit 5a5feb1e authored by Megan Henning's avatar Megan Henning Committed by GitHub
Browse files

Merge pull request #769 from scitran/template-rename

Clean up existing project templates mentioning `measurement` instead of `measurements`
parents ee7aee01 e05a8510
No related branches found
No related tags found
No related merge requests found
......@@ -235,10 +235,11 @@ def is_session_compliant(session, template):
return False
acquisitions = list(config.db.acquisitions.find({'session': session['_id']}))
for req in a_requirements:
min_count = req.pop('minimum')
req_temp = copy.deepcopy(req)
min_count = req_temp.pop('minimum')
count = 0
for a in acquisitions:
if not check_cont(a, req):
if not check_cont(a, req_temp):
# Didn't find a match, on to the next one
continue
else:
......
......@@ -14,11 +14,12 @@ import time
from api import config
from api.dao import containerutil
from api.dao.containerstorage import ProjectStorage
from api.jobs.jobs import Job
from api.jobs import gears
from api.types import Origin
CURRENT_DATABASE_VERSION = 26 # An int that is bumped when a new schema change is made
CURRENT_DATABASE_VERSION = 27 # An int that is bumped when a new schema change is made
def get_db_version():
......@@ -967,6 +968,29 @@ def upgrade_to_26():
process_cursor(cursor, upgrade_to_26_closure)
def upgrade_to_27():
"""
scitran/core PR #768
Fix project templates that reference `measurement` instead of `measurements`
Update all session compliance for affected projects
"""
projects = config.db.projects.find({'template.acquisitions.files.measurement': {'$exists': True}})
storage = ProjectStorage()
for p in projects:
template = p.get('template', {})
for a in template.get('acquisitions', []):
for f in a.get('files', []):
if f.get('measurement'):
f['measurements'] = f.pop('measurement')
config.log.debug('the template is now {}'.format(template))
config.db.projects.update_one({'_id': p['_id']}, {'$set': {'template': template}})
storage.recalc_sessions_compliance(project_id=str(p['_id']))
def upgrade_schema():
"""
Upgrades db to the current schema version
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment