'Converts a record from version 1 to version 2. Version 2
discards service names when they have been found from
nmap-services file.'

@staticmethod
def migrate_schema_hosts_1_2(doc):

    assert (doc['schema_version'] == 1)
    update = {'$set': {'schema_version': 2}}
    update_ports = False
    for port in doc.get('ports', []):
        if (port.get('service_method') == 'table'):
            update_ports = True
            for key in list(port):
                if key.startswith('service_'):
                    del port[key]
    if update_ports:
        update['$set']['ports'] = doc['ports']
    return update
