<?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="IN-10370_create_ASSIGNED_TO:1" author="borisuvarov" run-on-change="true" run-always="true">
        <precondition>
            <sqlquery>
                <![CDATA[
                    SELECT DISTINCT
                        v.assigned_to AS assigned_to,
                        v.vendor_id AS vendor_id
                    FROM ORCHARD_APP_REPORTING_V2.ART_RELATIONS_PROD_ART_RELATIONS.vendor v
                    INNER JOIN ORCHARD_APP_REPORTING_V2.ART_RELATIONS_PROD_ART_RELATIONS.orchadmin_users o_u
                        ON o_u.id = v.assigned_to
                    ;
               ]]>
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
            MATCH (v:Vendor {vendorId: toInteger(event.VENDOR_ID)})
            WITH v, event
            MATCH (p:Profile {profileId: toInteger(event.ASSIGNED_TO)}) WHERE p.profileType = 'OrchAdminProfile'
            WITH v, p
            MERGE (v)-[at:ASSIGNED_TO]->(p)
                ON CREATE SET
                    at.createdAt = datetime(),
                    at.createdBy = 'database/IN-10370_create_ASSIGNED_TO:1',
                    at.lastModifiedAt = datetime(),
                    at.lastModifiedBy = 'database/IN-10370_create_ASSIGNED_TO:1'
            ]]>
        </cypherquery>
    </changeset>
</changelog>
