<?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_2138_create_documents_profile:1" author="vsvirskiy">
        <neo4j:cypher>
            MATCH (i:Identity)
            WHERE i.id = '8fa71ad1-f02c-4191-8c78-9ffa45b57346'
            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_2138_create_documents_profile:1',
                lastModifiedBy: 'database/TAP_2138_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>
