def METHOD_NAME():
    op.add_column('membership', sa.Column('active_during', TSTZRANGE))
    op.execute("update membership set active_during = tstzrange(begins_at, ends_at, '[]')")
    op.alter_column('membership', 'active_during', nullable=False)
    op.drop_index('ix_membership_begins_at', table_name='membership')
    op.drop_index('ix_membership_ends_at', table_name='membership')
    op.create_index('ix_active_during', 'membership', ['active_during'],
                    unique=False, postgresql_using='gist')
    op.drop_column('membership', 'ends_at')
    op.drop_column('membership', 'begins_at')
    op.execute("""
    CREATE OR REPLACE FUNCTION evaluate_properties(evaluation_time timestamp with time zone)
        RETURNS TABLE
                (
                    user_id       integer,
                    property_name character varying,
                    denied        boolean
                )
        LANGUAGE sql
        STABLE
    AS $function$
    SELECT "user".id AS user_id, property.name AS property_name, false AS denied
    FROM membership
             JOIN ("group" JOIN property_group ON "group".id = property_group.id)
                  ON "group".id = membership.group_id
             JOIN "user" ON "user".id = membership.user_id
             JOIN property ON property_group.id = property.property_group_id
    WHERE membership.active_during @> evaluation_time
    GROUP BY "user".id, property.name
    HAVING every(property.granted)
    UNION
    SELECT "user".id AS user_id, property.name AS property_name, true AS denied
    FROM membership
             JOIN ("group" JOIN property_group ON "group".id = property_group.id)
                  ON "group".id = membership.group_id
             JOIN "user" ON "user".id = membership.user_id
             JOIN property ON property_group.id = property.property_group_id
    WHERE membership.active_during @> evaluation_time
    GROUP BY "user".id, property.name
    HAVING bool_or(property.granted) AND NOT every(property.granted)
    $function$ """)