<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://www.liquigraph.org/schema/1.0/liquigraph.xsd">
    <changeset id="KDH-156_vendor_to_d3_p5:1" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)<-[gpToLp:REPRESENTS]-(gp:GlobalParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    RETURN pr, lp, gpToLp, gp;
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.id = datetime.realtime().epochMillis,
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime(),
                            nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:1'
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlp.lastModifiedAt = datetime(),
                            nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:1'
                    WITH *
                    CALL apoc.merge.relationship(gp, type(gpToLp), null, gpToLp, nlp)
                    YIELD rel AS rel
                    RETURN nlp as labelParticipant;
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:2" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lpToT]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo)
                    WHERE lp.subaccountId <> pr.subaccountId
                    RETURN pr, lp, cf, ai
                ",
                "
                CALL apoc.util.sleep(1)
                MERGE (nlp:LabelParticipant:Orchard {name: lp.name, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                    ON CREATE SET
                        nlp.id = datetime.realtime().epochMillis,
                        nlp.uuid = apoc.create.uuid(),
                        nlp.createdAt = datetime(),
                        nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:2'
                    SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                        nlp.lastModifiedAt = datetime(),
                        nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:2'
                WITH *
                CALL apoc.merge.relationship(nlp, type(cf), null, cf, ai)
                YIELD rel AS rel
                RETURN nlp as labelParticipant",
                  {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:3" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (pr:Project {id: toInteger(event.PROJECT_ID)})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(:ArtistInfo)
                WHERE lp.subaccountId <> pr.subaccountId
                DELETE cf;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:4" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[lpToT:PARTICIPATED_IN]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    RETURN pr, lp, lpToT, t
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: pr.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.id = datetime.realtime().epochMillis,
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime(),
                            nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:4'
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlp.lastModifiedAt = datetime(),
                            nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:4'
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(lpToT), {participated_as: lpToT.participated_as}, lpToT, t)
                    YIELD rel AS rel1
                    RETURN nlp as labelParticipant
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:5" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MATCH (lp)-[cf:CREATED_FROM]->(ta:TrackArtist)<-[:HAS_SOURCE_ARTIST]-(t)
                    RETURN pr, lp, cf, ta
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.id = datetime.realtime().epochMillis,
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime(),
                            nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:5'
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlp.lastModifiedAt = datetime(),
                            nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:5'
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(cf), null, cf, ta)
                    YIELD rel AS rel
                    RETURN nlp as labelParticipant
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:6" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MATCH (lp)-[cf:CREATED_FROM]->(tw:TrackWriter)<-[:HAS_SOURCE_ARTIST]-(t)
                    RETURN pr, lp, cf, tw
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.id = datetime.realtime().epochMillis,
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime(),
                            nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:6'
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlp.lastModifiedAt = datetime(),
                            nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:6'
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(cf), null, cf, tw)
                    YIELD rel AS rel
                    RETURN nlp as labelParticipant
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:7" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (pr:Project {id: toInteger(event.PROJECT_ID)})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)<-[lpToT:PARTICIPATED_IN]-(lp:LabelParticipant)
                WHERE lp.subaccountId <> pr.subaccountId
                OPTIONAL MATCH (lp)-[lpToTa:CREATED_FROM]->(:TrackArtist)<-[:HAS_SOURCE_ARTIST]-(t)
                OPTIONAL MATCH (lp)-[lpToTw:CREATED_FROM]->(:TrackWriter)<-[:HAS_SOURCE_ARTIST]-(t)
                DELETE lpToT, lpToTa, lpToTw;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:8" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)<-[gpToLp:REPRESENTS]-(gp:GlobalParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    RETURN pr, lp, gpToLp, gp
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                    ON CREATE SET
                        nlp.id = datetime.realtime().epochMillis,
                        nlp.uuid = apoc.create.uuid(),
                        nlp.createdAt = datetime(),
                        nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:8'
                    SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                        nlp.lastModifiedAt = datetime(),
                        nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:8'
                    WITH *
                    CALL apoc.merge.relationship(gp, type(gpToLp), null, gpToLp, nlp)
                    YIELD rel AS rel
                    RETURN nlp as labelParticipant
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:9" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(p:Product)<-[lpToP:PARTICIPATED_IN]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    RETURN pr, lp, lpToP, p
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.id = datetime.realtime().epochMillis,
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime(),
                            nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:9'
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlp.lastModifiedAt = datetime(),
                            nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:9'
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(lpToP), {participated_as: lpToP.participated_as}, lpToP, p)
                    YIELD rel AS rel
                    RETURN nlp as labelParticipant
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:10" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo)
                    WHERE lp.subaccountId <> pr.subaccountId
                    RETURN pr, lp, cf, ai
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.id = datetime.realtime().epochMillis,
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime(),
                            nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:10'
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlp.lastModifiedAt = datetime(),
                            nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:10'
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(cf), null, cf, ai)
                    YIELD rel AS rel
                    RETURN nlp as labelParticipant
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:11" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (pr:Project {id: toInteger(event.PROJECT_ID)})-[:INCLUDES]->(:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)-[cf:CREATED_FROM]->(:ArtistInfo)
                WHERE lp.subaccountId <> pr.subaccountId
                DELETE cf;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:12" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(p:Product)<-[:PARTICIPATED_IN]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    MATCH (lp)-[lpToRa:CREATED_FROM]->(ra:ReleaseArtist {productId: p.id})
                    RETURN pr, lp, lpToRa, ra
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.id = datetime.realtime().epochMillis,
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime(),
                            nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:12'
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlp.lastModifiedAt = datetime(),
                            nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:12'
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(lpToRa), null, lpToRa, ra)
                    YIELD rel AS rel
                    RETURN nlp as labelParticipant
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:13" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (pr:Project {id: toInteger(event.PROJECT_ID)})-[:INCLUDES]->(p:Product)<-[lpToP:PARTICIPATED_IN]-(lp:LabelParticipant)
                WHERE lp.subaccountId <> pr.subaccountId
                OPTIONAL MATCH (lp)-[lpToRa:CREATED_FROM]->(:ReleaseArtist {productId: p.id})
                DELETE lpToP, lpToRa;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:14" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant)-[cf:CREATED_FROM]->(ai:ArtistInfo)
                    WHERE lp.subaccountId <> pr.subaccountId
                    RETURN pr, lp, cf, ai
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.id = datetime.realtime().epochMillis,
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime(),
                            nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:14'
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlp.lastModifiedAt = datetime(),
                            nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:14'
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(cf), null, cf, ai)
                    YIELD rel AS rel
                    RETURN nlp as labelParticipant
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:15" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (pr:Project {id: toInteger(event.PROJECT_ID)})-[:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant)-[cf:CREATED_FROM]->(:ArtistInfo)
                WHERE lp.subaccountId <> pr.subaccountId
                DELETE cf;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:16" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[lpToP:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    RETURN pr, lp, lpToP
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.id = datetime.realtime().epochMillis,
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime(),
                            nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:16'
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlp.lastModifiedAt = datetime(),
                            nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:16'
                    WITH *
                    CALL apoc.merge.relationship(pr, type(lpToP), null, lpToP, nlp)
                    YIELD rel AS rel
                    RETURN nlp as labelParticipant
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:17" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (pr:Project {id: toInteger(event.PROJECT_ID)})-[lpToP:CREATED_FOR_PARTICIPANT]->(lp:LabelParticipant)
                WHERE lp.subaccountId <> pr.subaccountId
                DELETE lpToP;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:18" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)-[:IS_PLACEMENT_OF]->(:LabelSoundRecording)<-[:ON_LABEL_SOUND_RECORDING]-(lsrp:LabelSoundRecordingParticipation)<-[hlsrp:HAS_LABEL_SOUND_RECORDING_PARTICIPATION]-(lp:LabelParticipant)
                    WHERE lp.subaccountId <> pr.subaccountId
                    RETURN pr, lp, hlsrp, lsrp
                ",
                "
                    CALL apoc.util.sleep(1)
                    MERGE (nlp:LabelParticipant:Orchard {normalizedName: lp.normalizedName, vendorId: lp.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlp.id = datetime.realtime().epochMillis,
                            nlp.uuid = apoc.create.uuid(),
                            nlp.createdAt = datetime(),
                            nlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:18'
                        SET nlp += apoc.map.removeKeys(lp, ['id', 'uuid', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlp.lastModifiedAt = datetime(),
                            nlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:18'
                    WITH *
                    CALL apoc.merge.relationship(nlp, type(hlsrp), null, hlsrp, lsrp)
                    YIELD rel AS rel
                    RETURN nlp as labelParticipant
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:19" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (pr:Project {id: toInteger(event.PROJECT_ID)})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT]->(lsr:LabelSoundRecording)<-[:ON_LABEL_SOUND_RECORDING]-(lsrp:LabelSoundRecordingParticipation)<-[hlsrp:HAS_LABEL_SOUND_RECORDING_PARTICIPATION]-(lp:LabelParticipant)
                WHERE lp.subaccountId <> pr.subaccountId
                DELETE hlsrp;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:20" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT]-(lsr:LabelSoundRecording)<-[olsr:ON_LABEL_SOUND_RECORDING]-(lsrp:LabelSoundRecordingParticipation)
                    WHERE lsr.subaccountId <> pr.subaccountId
                    RETURN pr, lsr, olsr, lsrp
                ",
                "
                    MERGE (nlsr:LabelSoundRecording:Orchard {isrc: lsr.isrc, vendorId: pr.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlsr.id = apoc.create.uuid(),
                            nlsr.createdAt = datetime(),
                            nlsr.createdBy = 'database/KDH-156_vendor_to_d3_p5:20'
                        SET nlsr += apoc.map.removeKeys(lsr, ['id', 'isrc', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlsr.lastModifiedAt = datetime(),
                            nlsr.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:20'
                    WITH *
                    CALL apoc.merge.relationship(lsrp, type(olsr), {}, olsr, nlsr)
                    YIELD rel
                    RETURN nlsr as labelSoundRecording
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:21" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (pr:Project {id: toInteger(event.PROJECT_ID)})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT]-(lsr:LabelSoundRecording)<-[olsr:ON_LABEL_SOUND_RECORDING]-(lsrp:LabelSoundRecordingParticipation)
                WHERE lsr.subaccountId <> pr.subaccountId
                DELETE olsr;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:22" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)-[:IS_PLACEMENT_OF]->(lsr:LabelSoundRecording)<-[lsrToGsr:REPRESENTS]-(gsr:GlobalSoundRecording)
                    WHERE lsr.subaccountId <> pr.subaccountId
                    RETURN pr, lsr, lsrToGsr, gsr
                ",
                "
                    MERGE (nlsr:LabelSoundRecording:Orchard {isrc: lsr.isrc, vendorId: pr.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlsr.id = apoc.create.uuid(),
                            nlsr.createdAt = datetime(),
                            nlsr.createdBy = 'database/KDH-156_vendor_to_d3_p5:22'
                        SET nlsr += apoc.map.removeKeys(lsr, ['id', 'isrc', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlsr.lastModifiedAt = datetime(),
                            nlsr.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:22'
                    WITH *
                    CALL apoc.merge.relationship(gsr, type(lsrToGsr), null, lsrToGsr, nlsr)
                    YIELD rel
                    RETURN true
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:23" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                CALL apoc.periodic.iterate(
                "
                    MATCH (pr:Project {id: $project_id})-[:INCLUDES]->(:Product)-[:INCLUDES]->(t:Track)-[lsrToT:IS_PLACEMENT_OF]->(lsr:LabelSoundRecording)
                    WHERE lsr.subaccountId <> pr.subaccountId
                    RETURN pr, lsr, lsrToT, t
                ",
                "
                    MERGE (nlsr:LabelSoundRecording:Orchard {isrc: lsr.isrc, vendorId: pr.vendorId, subaccountId: pr.subaccountId})
                        ON CREATE SET
                            nlsr.id = apoc.create.uuid(),
                            nlsr.createdAt = datetime(),
                            nlsr.createdBy = 'database/KDH-156_vendor_to_d3_p5:23'
                        SET nlsr += apoc.map.removeKeys(lsr, ['id', 'isrc', 'vendorId', 'subaccountId', 'createdAt', 'createdBy']),
                            nlsr.lastModifiedAt = datetime(),
                            nlsr.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:23'
                    WITH *
                    CALL apoc.merge.relationship(t, type(lsrToT), null, lsrToT, nlsr)
                    YIELD rel
                    RETURN nlsr as labelSoundRecording
                ",
                {batchSize:1, iterateList:true, parallel:false, params: {project_id: toInteger(event.PROJECT_ID)}}
                )
                YIELD total, failedOperations, errorMessages, failedBatches, batch
                RETURN total, failedOperations, errorMessages, failedBatches, batch;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:24" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT PROJECT_ID
                FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project
                WHERE project_id in (2860616, 3288916, 3460181, 3468867, 3739421, 3774367, 3857664, 3860621, 3860622, 3913374, 3926280, 3946286, 3946453, 3958241, 3978777, 3979455, 4048134, 4050932, 4051838, 4060290, 4060292, 4060326, 4060328, 4068624, 4155483, 4166543, 4167746, 4173627, 4175062, 4181989, 4186657, 4189151, 4193132, 4197968, 4198844, 4207508, 4232206, 4236904, 4237753, 4242624, 4243666, 4256020, 4266355, 4266595, 4267985, 4271026, 4275179, 4279003, 4279552, 4279910, 4289952, 4291373, 4301350, 4301632, 4305540, 4308042, 4308067, 4335799, 4335883, 4346276, 4383967, 4385914, 4387275, 4408915, 4415856, 4424985, 4442162, 4633509, 4693398, 4768875, 4769438, 4781150, 4782748, 5024689, 5029326, 5032848, 5049277, 5049341, 5049856, 5049859, 5060155, 5060497, 5060573, 5066807, 5066817, 5066830, 5066839, 5066845, 5066850, 5066858, 5070795, 5070799, 5070821, 5070823, 5070831, 5487416, 5624309, 5641127, 5676754, 5683824, 5710264, 5732594)
                ORDER BY project_id;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (pr:Project {id: toInteger(event.PROJECT_ID)})-[:INCLUDES]->(:Product)-[:INCLUDES]->(:Track)-[lsrToT:IS_PLACEMENT_OF]->(lsr:LabelSoundRecording)
                WHERE lsr.subaccountId <> pr.subaccountId
                DELETE lsrToT;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:25" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT 1;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (lp:LabelParticipant)<-[sahlp:HAS_LABEL_PARTICIPANT]-(sa:Subaccount)
                WHERE lp.vendorId in [11494, 11933, 16055, 18063, 20151, 20905, 21899, 22250, 22295, 22566, 22567, 22699, 23560, 24430, 24565, 24994, 25153, 25170, 25223, 25248, 25483, 25652, 26107, 26217, 26673, 26686, 26726, 26802, 26814, 26849, 27078, 27153, 27305, 27323, 27358, 28058, 28271, 28323, 28462, 28603, 28704, 28710, 28714, 28943, 29138, 29449, 29891, 30557, 32171, 32205, 32221, 32412, 32420, 32423, 32621, 32679, 32824, 32957, 33043, 33134, 33580, 66962, 76160, 78440, 78487, 82366] and lp.subaccountId <> sa.id
                DELETE sahlp;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="KDH-156_vendor_to_d3_p5:26" author="ssavva" run-always="true">
        <precondition>
            <sqlquery>
                SELECT 1;
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (lp:LabelParticipant)
                WHERE lp.vendorId in [11494, 11933, 16055, 18063, 20151, 20905, 21899, 22250, 22295, 22566, 22567, 22699, 23560, 24430, 24565, 24994, 25153, 25170, 25223, 25248, 25483, 25652, 26107, 26217, 26673, 26686, 26726, 26802, 26814, 26849, 27078, 27153, 27305, 27323, 27358, 28058, 28271, 28323, 28462, 28603, 28704, 28710, 28714, 28943, 29138, 29449, 29891, 30557, 32171, 32205, 32221, 32412, 32420, 32423, 32621, 32679, 32824, 32957, 33043, 33134, 33580, 66962, 76160, 78440, 78487, 82366] AND lp.subaccountId <> 0
                MATCH (v:Vendor)
                WHERE v.id = lp.vendorId
                MATCH (sa:Subaccount)
                WHERE sa.id = lp.subaccountId
                MERGE (v)-[vhlp:HAS_LABEL_PARTICIPANT]->(lp)
                    ON CREATE SET
                        vhlp.createdAt = datetime(),
                        vhlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:26',
                        vhlp.lastModifiedAt = datetime(),
                        vhlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:26'
                MERGE (sa)-[sahlp:HAS_LABEL_PARTICIPANT]->(lp)
                    ON CREATE SET
                        sahlp.createdAt = datetime(),
                        sahlp.createdBy = 'database/KDH-156_vendor_to_d3_p5:26',
                        sahlp.lastModifiedAt = datetime(),
                        sahlp.lastModifiedBy = 'database/KDH-156_vendor_to_d3_p5:26'
                RETURN true;
            ]]>
        </cypherquery>
    </changeset>
</changelog>
