'Converts a record from version 3 to version 4. Version 4
creates a "fake" port entry to store host scripts.'

@staticmethod
def migrate_schema_hosts_3_4(doc):

    assert (doc['schema_version'] == 3)
    update = {'$set': {'schema_version': 4}}
    if ('scripts' in doc):
        doc.setdefault('ports', []).append({'port': 'host', 'scripts': doc.pop('scripts')})
        update['$set']['ports'] = doc['ports']
        update['$unset'] = {'scripts': True}
    return update
