'Converts a record from version 5 to version 6. Version 6 uses Nmap
structured data for scripts using the vulns NSE library.'

@staticmethod
def __migrate_schema_hosts_5_6(doc):

    assert (doc['schema_version'] == 5)
    doc['schema_version'] = 6
    migrate_scripts = set((script for (script, alias) in viewitems(xmlnmap.ALIASES_TABLE_ELEMS) if (alias == 'vulns')))
    for port in doc.get('ports', []):
        for script in port.get('scripts', []):
            if (script['id'] in migrate_scripts):
                table = None
                if (script['id'] in script):
                    table = script.pop(script['id'])
                    script['vulns'] = table
                elif ('vulns' in script):
                    table = script['vulns']
                else:
                    continue
                newtable = xmlnmap.change_vulns(table)
                if (newtable != table):
                    script['vulns'] = newtable
