def persist_unique_identifiers(metamodel, path, mode='w'):
    """
    Persist all unique identifiers in a *metamodel* by serializing them and
    saving to a *path* on disk.
    """
    with open(path, mode) as f:
        for metaclass in metamodel.metaclasses.values():
            for index_name, attribute_names in metaclass.indices.items():
                attribute_names = ', '.join(attribute_names)
                s = 'CREATE UNIQUE INDEX %s ON %s (%s);\n' % (index_name,
                    metaclass.kind, attribute_names)
                f.write(s)
