<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.liquigraph.org/schema/1.0/liquigraph.xsd">
    <changeset id="DISTRO-4674_modify_setLabelParticipantNormalizedName:1" author="owright" run-on-change="true">
        <query>
            CALL apoc.trigger.remove('setLabelParticipantNormalizedName');
        </query>
    </changeset>
    <changeset id="DISTRO-4674_modify_setLabelParticipantNormalizedName:2" author="owright" run-on-change="true">
        <query>
            CALL apoc.trigger.add(
                'setLabelParticipantNormalizedName',
                '
                    WITH "(?ms).+-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" AS uuidNamePattern
                    UNWIND apoc.trigger.nodesByLabel($assignedNodeProperties, "LabelParticipant") AS n
                    SET n.normalizedName = CASE WHEN n.normalizedName =~ uuidNamePattern THEN toLower(trim(apoc.text.regreplace(n.name, "[ ]+", ""))) + "-" + n.uuid ELSE toLower(trim(apoc.text.regreplace(n.name, "[ ]+", ""))) END
                ',
                {phase: 'before'}
            );
        </query>
    </changeset>
</changelog>
