def _ensure_aggregate(ctx, agg_uuid):
    """Finds an aggregate and returns its UUID (which is the same as the
    supplied parameter). If not found, creates the aggregate with the supplied
    UUID and returns the new aggregate's UUID.
    """
    query = """
            MERGE (agg:AGGREGATE {uuid: '%s'})
            RETURN agg
    """ % agg_uuid
    result = ctx.tx.run(query).data()
    return agg_uuid