<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <!-- Delete agreement-composition relationship -->
    <changeset id="PUB-801_cleanup_songid_7242:1" author="jmarais" run-always="true">
        <cypherquery>
            <![CDATA[
                MATCH (c:PublishingComposition)-[rel:HAS_AGREEMENT]-(pa:PublishingAgreement { id: "930e151c-f6ff-4f23-89dd-abf32daf3213"})
                DETACH DELETE rel
            ]]>
        </cypherquery>
    </changeset>
    <!-- Create Elliot Mechanic songWriter -->
    <changeset id="PUB-801_cleanup_agreements:2" author="jmarais" run-always="true">
        <cypherquery>
            <![CDATA[
                MATCH (v:Vendor { vendorId: 16476 })
                WITH v
                MERGE (v)-[rel:HAS_SIGNED_WRITER]->(s:PublishingSongWriter { ipi: "00200901723" })
                ON CREATE
                    SET
                        s.legalName = 'Elliot Mechanic',
                        s.pro = 'SOCAN',
                        s.pubWriterID = 13,
                        s.labelUUID = '2015aed8-1ca5-4134-b4ee-e75be4a87674',
                        s.id = apoc.create.uuid(),
                        s.createdAt = datetime(),
                        s.lastModifiedAt = datetime(),
                        s.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        s.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242',
                        rel.createdAt = datetime(),
                        rel.lastModifiedAt = datetime(),
                        rel.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        rel.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242'
                RETURN s
            ]]>
        </cypherquery>
    </changeset>
    <!-- Create Cussy Music Publishing publisher. Create agreement. Connect composition-agreement-writer and agreement-publisher -->
    <changeset id="PUB-801_cleanup_songid_7242:3" author="jmarais" run-always="true">
        <cypherquery>
            <![CDATA[
                MATCH (v:Vendor { vendorId: 16476 })
                WITH v
                MERGE (v)-[rel:HAS_ASSOCIATED_PUBLISHER]->(p:PublishingPublisher { ipi: "00266406364" })
                ON CREATE
                    SET
                        p.name = 'Cussy Music Publishing',
                        p.pro = 'SOCAN',
                        p.pubPublisherID = 4,
                        p.labelUUID = '2015aed8-1ca5-4134-b4ee-e75be4a87674',
                        p.createdAt = datetime(),
                        p.lastModifiedAt = datetime(),
                        p.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        p.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242',
                        p.id = apoc.create.uuid(),
                        rel.createdAt = datetime(),
                        rel.lastModifiedAt = datetime(),
                        rel.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        rel.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242'
                WITH p
                MERGE (a:PublishingAgreement {
                    controlled: true,
                    labelUUID: 16476,
                    pubPublisherID: 4,
                    pubWriterID: 13
                })
                ON CREATE
                    SET
                        a.id = apoc.create.uuid()
                WITH p, a
                MATCH (c:PublishingComposition { id: "967bcbc4-3dca-4eb5-a557-c72fd8c8bc2e" })
                WITH p, a, c
                MATCH (v:Vendor { vendorId: 16476 })-[:HAS_SIGNED_WRITER]-(s:PublishingSongWriter { ipi: "00200901723" })
                WITH p, a, c, s
                MERGE (c)-[agreementRel:HAS_AGREEMENT]->(a)<-[writerRel:HAS_AGREEMENT]-(s)
                ON CREATE
                    SET
                        agreementRel.containsPublicDomain = false,
                        agreementRel.containsSample = false,
                        agreementRel.hasLyricsContribution = true,
                        agreementRel.hasMusicContribution = true,
                        agreementRel.split = 33.33,
                        agreementRel.createdAt = datetime(),
                        agreementRel.lastModifiedAt = datetime(),
                        agreementRel.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        agreementRel.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242',
                        writerRel.createdAt = datetime(),
                        writerRel.lastModifiedAt = datetime(),
                        writerRel.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        writerRel.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242'
                WITH a, p
                MERGE (p)-[publisherRel:HAS_AGREEMENT]->(a)
                ON CREATE
                    SET
                        publisherRel.createdAt = datetime(),
                        publisherRel.lastModifiedAt = datetime(),
                        publisherRel.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        publisherRel.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242'
                RETURN p
            ]]>
        </cypherquery>
    </changeset>
    <!-- Create Me and You Music publisher. Create agreement. Connect composition-agreement-writer and agreement-publisher -->
     <changeset id="PUB-801_cleanup_songid_7242:4" author="jmarais" run-always="true">
        <cypherquery>
            <![CDATA[
                MATCH (v:Vendor { vendorId: 16476 })
                WITH v
                MERGE (v)-[rel:HAS_ASSOCIATED_PUBLISHER]->(p:PublishingPublisher { ipi: "00519922042" })
                ON CREATE
                    SET
                        p.name = 'Me and You Music',
                        p.pubPublisherID = 16,
                        p.labelUUID = '2015aed8-1ca5-4134-b4ee-e75be4a87674',
                        p.createdAt = datetime(),
                        p.lastModifiedAt = datetime(),
                        p.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        p.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242',
                        p.id = apoc.create.uuid(),
                        rel.createdAt = datetime(),
                        rel.lastModifiedAt = datetime(),
                        rel.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        rel.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242'
                WITH p
                MERGE (a:PublishingAgreement {
                    controlled: true,
                    labelUUID: 16476,
                    pubPublisherID: 16,
                    pubWriterID: 13
                })
                ON CREATE
                    SET
                        a.id = apoc.create.uuid()
                WITH p, a
                MATCH (c:PublishingComposition { id: "967bcbc4-3dca-4eb5-a557-c72fd8c8bc2e" })
                WITH p, a, c
                MATCH (v:Vendor { vendorId: 16476 })-[:HAS_SIGNED_WRITER]-(s:PublishingSongWriter { ipi: "00200901723" })
                WITH p, a, c, s
                MERGE (c)-[agreementRel:HAS_AGREEMENT]->(a)<-[writerRel:HAS_AGREEMENT]-(s)
                ON CREATE
                    SET
                        agreementRel.containsPublicDomain = false,
                        agreementRel.containsSample = false,
                        agreementRel.hasLyricsContribution = true,
                        agreementRel.hasMusicContribution = true,
                        agreementRel.split = 33.33,
                        agreementRel.createdAt = datetime(),
                        agreementRel.lastModifiedAt = datetime(),
                        agreementRel.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        agreementRel.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242',
                        writerRel.createdAt = datetime(),
                        writerRel.lastModifiedAt = datetime(),
                        writerRel.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        writerRel.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242'
                WITH a, p
                MERGE (p)-[publisherRel:HAS_AGREEMENT]->(a)
                ON CREATE
                    SET
                        publisherRel.createdAt = datetime(),
                        publisherRel.lastModifiedAt = datetime(),
                        publisherRel.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        publisherRel.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242'
                RETURN p
            ]]>
        </cypherquery>
    </changeset>
    <!-- Connect songWriter to existing agreement -->
    <changeset id="PUB-801_cleanup_songid_7242:5" author="jmarais" run-always="true">
        <cypherquery>
            <![CDATA[
                MATCH (v:Vendor { vendorId: 16476 })-[:HAS_SIGNED_WRITER]->(s:PublishingSongWriter { ipi: "00200901723" })
                MATCH (a:PublishingAgreement { id: "43476857-f51b-4a6f-bcd1-dfb219af9c9f" })
                MERGE (s)-[rel:HAS_AGREEMENT]->(a)
                ON CREATE
                    SET
                        rel.createdAt = datetime(),
                        rel.lastModifiedAt = datetime(),
                        rel.createdBy = 'database/PUB-801_cleanup_songid_7242',
                        rel.lastModifiedBy = 'database/PUB-801_cleanup_songid_7242'
                RETURN s
            ]]>
        </cypherquery>
    </changeset>
</changelog>
