<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:/var/app/InputFileSchema.xsd">
    <changeset id="KDH-99_fix_backfill_label_participant_ref_uuids:1" author="rtorres" run-always="true">
        <precondition>
            <sqlquery>
                <![CDATA[
                    SELECT ID
                    FROM FACTS.PROD.LABEL_PARTICIPANT
                    WHERE COMPANY_BRAND_UUID IS NULL;
                ]]>
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (lp:LabelParticipant {id: toInteger(event.ID)})
                OPTIONAL MATCH (lp)<-[:HAS_LABEL_PARTICIPANT]-(v:Vendor)
                OPTIONAL MATCH (v)<-[:HAS_LABEL]-(cb:CompanyBrand)
                OPTIONAL MATCH (lp)<-[:HAS_LABEL_PARTICIPANT]-(sa:Subaccount)
                SET lp.companyBrandUUID = cb.uuid,
                    lp.vendorUUID = v.uuid,
                    lp.subaccountUUID = sa.uuid,
                    lp.lastModifiedAt=datetime(),
                    lp.lastModifiedBy='database/KDH-99_fix_backfill_label_participant_ref_uuids'
            ]]>
        </cypherquery>
    </changeset>
</changelog>
