<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./schema.xsd">
    <changeset id="TAP-902-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-902-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-902-grant-access:2" author="j0shua" run-always="true">
        <cypherquery>
            <![CDATA[
                MATCH (v:Vendor {id: '*'})

                MATCH (identity:Identity {
                    id: "38108b99-9c4e-4924-889c-99c5fd1ca01f"
                })

                MERGE (identity)-[hp:HAS_PROFILE]->(p:Profile { profileType: 'DocumentsProfile' })
                SET
                    p.fullCatalogAccess = true,
                    p.updatedBy = 'database/TAP-902-grant-access',
                    p.updatedOn = datetime(),
                    p.lastModifiedAt = datetime(),
                    p.lastModifiedBy = 'database/TAP-902-grant-access',
                    hp.createdAt = datetime(),
                    hp.updatedBy = 'database/TAP-902-grant-access',
                    hp.updatedOn = datetime()

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

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