<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./schema.xsd">
    <changeset id="TAP-888-grant-access:1" author="j0shua" run-always="true">
        <cypherquery>
            <![CDATA[
                MATCH (identity:Identity {
                    email: "jessica.farquharson@awal.com"
                })-[:HAS_PROFILE]->(p:Profile {
                    profileType: 'DocumentsProfile'
                }) -[rel:DELETED_HAS_ACCESS_TO]->(v:Vendor {id: '*'})

                SET
                    rel.updatedBy = 'database/TAP-888-grant-access',
                    rel.updatedOn = datetime()

                 WITH rel
                 CALL apoc.refactor.setType(rel, 'HAS_ACCESS_TO')
                 YIELD input, output
                 RETURN true;
            ]]>
        </cypherquery>
    </changeset>
    <changeset id="TAP-888-grant-access:2" author="j0shua" run-always="true">
        <cypherquery>
            <![CDATA[
                MATCH (v:Vendor {id: '*'})

                MATCH (identity:Identity {
                    email: "cfreeman@theorchard.com"
                })

                MERGE (inc:IncrementId {nodeName: 'Profile'})
                    ON CREATE SET inc.id = 2
                    ON MATCH SET inc.id = inc.id + 1

                MERGE (identity)-[hp:HAS_PROFILE]->(p:Profile { profileType: 'DocumentsProfile' })
                ON CREATE SET
                    p.createdAt = datetime(),
                    p.uuid = apoc.create.uuid(),
                    p.profileId = inc.id - 1,
                    p.profileName = identity.name,
                    p.fullCatalogAccess = true,
                    p.roles = ['payee_management']
                SET
                    p.updatedBy = 'database/TAP-888-grant-access',
                    p.updatedOn = datetime(),
                    p.lastModifiedAt = datetime(),
                    p.lastModifiedBy = 'database/TAP-888-grant-access',
                    hp.createdAt = datetime(),
                    hp.updatedBy = 'database/TAP-888-grant-access',
                    hp.updatedOn = datetime()

                MERGE (p)-[hat:HAS_ACCESS_TO]->(v)
                SET
                    hat.createdAt = datetime(),
                    hat.updatedOn = datetime(),
                    hat.updatedBy = 'database/TAP-888-grant-access'

                return true;
            ]]>
        </cypherquery>
    </changeset>
</changelog>