<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:neo4j="http://www.liquibase.org/xml/ns/dbchangelog-ext"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
    <changeSet id="TAP-1723-create-documents-profile:1" author="rpashchenko">
        <neo4j:cypher>
            MATCH (i:Identity)
            WHERE i.id = '17af794b-a0a4-48ba-8d68-cb1b6768df80'
            MERGE (increment:IncrementId {nodeName: 'Profile'})
                ON CREATE SET increment.id = 2
                ON MATCH SET increment.id = increment.id + 1
            CREATE (p:Profile {
                profileId: (increment.id-1),
                profileType: 'DocumentsProfile',
                profileName: i.name,
                uuid: apoc.create.uuid(),
                roles: ['payee_management'],
                fullCatalogAccess: true,
                brand: 'orchard',
                createdAt: datetime(),
                lastModifiedAt: datetime(),
                createdBy: 'database/TAP-1723-create-documents-profile:1',
                lastModifiedBy: 'database/TAP-1723-create-documents-profile:1'
            })
            MERGE (i)-[:HAS_PROFILE]->(p)
            WITH p, i
            MATCH (v:Vendor {id: '*'})
            MERGE (p)-[:HAS_ACCESS_TO]->(v)            
            RETURN i,p;
        </neo4j:cypher>
    </changeSet>
</databaseChangeLog>
