Skip to content

Commit e736429

Browse files
committed
Add rule upgrade
1 parent de5ab51 commit e736429

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

bin/database.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ def upgrade_to_40():
13011301
cursor = config.db.acquisitions.find({'timestamp':{'$type':'string'}})
13021302
process_cursor(cursor, upgrade_to_40_closure)
13031303

1304-
def upgrade_to_40_closure(cont, cont_name):
1304+
def upgrade_files_to_40(cont, cont_name):
13051305
"""
13061306
if the file has a modality, we try to find a matching classification
13071307
key and value for each measurement in the modality's classification map
@@ -1350,6 +1350,21 @@ def upgrade_to_40_closure(cont, cont_name):
13501350

13511351
return True
13521352

1353+
def upgrade_rules_to_40(rule):
1354+
1355+
def adjust_type(r):
1356+
if r['type'] == 'file.measurement':
1357+
r['type'] = 'file.classification'
1358+
elif r['type'] == 'container.has-measurement':
1359+
r['type'] = 'container.has-classification'
1360+
1361+
for r in rule.get('any', []):
1362+
adjust_type(r)
1363+
1364+
for r in rule.get('all', []):
1365+
adjust_type(r)
1366+
1367+
config.db.project_rules.replace_one({'_id': rule['_id']}, rule)
13531368

13541369
def upgrade_to_40():
13551370
"""
@@ -1360,7 +1375,17 @@ def upgrade_to_40():
13601375
for cont_name in ['groups', 'projects', 'collections', 'sessions', 'acquisitions', 'analyses']:
13611376

13621377
cursor = config.db[cont_name].find({'files.measurements': {'$exists': True }})
1363-
process_cursor(cursor, upgrade_to_40_closure, context=cont_name)
1378+
process_cursor(cursor, upgrade_files_to_40, context=cont_name)
1379+
1380+
1381+
cursor = config.db.project_rules.find({'$or': [
1382+
{'all.type': {'$in': ['file.measurement', 'container.has-measurement']}},
1383+
{'any.type': {'$in': ['file.measurement', 'container.has-measurement']}}
1384+
]})
1385+
process_cursor(cursor, upgrade_rules_to_40)
1386+
1387+
1388+
13641389

13651390

13661391

raml/schemas/input/enginemetadata.json

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
"public": {"type": ["boolean", "null"]},
4141
"label": {"type": ["string", "null"]},
4242
"info": {"type": ["object", "null"]},
43-
"metadata": {"type": ["object", "null"]},
44-
"measurement": {"type": ["string", "null"]},
4543
"instrument": {"type": ["string", "null"]},
4644
"uid": {"type": ["string", "null"]},
4745
"timestamp": {"type": ["string", "null"], "format": "date-time"},

0 commit comments

Comments
 (0)