CLI upgrade_attachment_schema: skip already upgraded nodes.
This commit is contained in:
@@ -672,7 +672,6 @@ def upgrade_attachment_schema(proj_url=None, all_projects=False):
|
|||||||
for proj_nt in project['node_types']:
|
for proj_nt in project['node_types']:
|
||||||
nt_name = proj_nt['name']
|
nt_name = proj_nt['name']
|
||||||
if nt_name not in nts_by_name:
|
if nt_name not in nts_by_name:
|
||||||
log.info(' - skipping node type "%s"', nt_name)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
log.info(' - replacing attachment schema on node type "%s"', nt_name)
|
log.info(' - replacing attachment schema on node type "%s"', nt_name)
|
||||||
@@ -703,10 +702,14 @@ def upgrade_attachment_schema(proj_url=None, all_projects=False):
|
|||||||
'properties.attachments': {'$exists': True},
|
'properties.attachments': {'$exists': True},
|
||||||
})
|
})
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
|
attachments = node[u'properties'][u'attachments']
|
||||||
|
if isinstance(attachments, dict):
|
||||||
|
# This node has already been upgraded.
|
||||||
|
continue
|
||||||
|
|
||||||
log.info(' - Updating schema on node %s (%s)', node['_id'], node.get('name'))
|
log.info(' - Updating schema on node %s (%s)', node['_id'], node.get('name'))
|
||||||
new_atts = {}
|
new_atts = {}
|
||||||
|
for field_info in attachments:
|
||||||
for field_info in node[u'properties'][u'attachments']:
|
|
||||||
for attachment in field_info.get('files', []):
|
for attachment in field_info.get('files', []):
|
||||||
new_atts[attachment[u'slug']] = {u'oid': attachment[u'file']}
|
new_atts[attachment[u'slug']] = {u'oid': attachment[u'file']}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user