<?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="WAR-3391_vendor_star_access:1" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: 'bff0782f-5a83-43db-aaca-438acd8df1f7'})
                -[:HAS_PROFILE]->(profile:Profile {profileType: "MoneyhubProfile"})
                -[deleted_relationship:DELETED_HAS_ACCESS_TO]->(vendor:Vendor {id: '*'})
            DELETE deleted_relationship
            WITH profile, vendor
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3391_vendor_star_access:2" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: '496453f2-188b-4420-8be0-7fa07e5ff37c'})
                -[:HAS_PROFILE]->(profile:Profile {profileType: "MoneyhubProfile"})
                -[deleted_relationship:DELETED_HAS_ACCESS_TO]->(vendor:Vendor {id: '*'})
            DELETE deleted_relationship
            WITH profile, vendor
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3391_vendor_star_access:3" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: 'f5d3b4e1-6ad1-4305-833f-f2dacd0cfdc6'})
            MERGE (increment:IncrementId {nodeName: 'Profile'})
                ON CREATE SET increment.id = 2
                ON MATCH SET increment.id = increment.id + 1
            CREATE (profile:Profile {
                profileId: (increment.id),
                profileType: 'MoneyhubProfile',
                profileName: identity.name,
                brand: identity.defaultBrand,
                fullCatalogAccess: true,
                roles: ['accounting'],
                uuid: apoc.create.uuid(),
                createdAt: datetime(),
                lastModifiedAt: datetime(),
                createdBy: 'database/WAR-3391_vendor_star_access:3',
                lastModifiedBy: 'database/WAR-3391_vendor_star_access:3'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3391_vendor_star_access:4" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: '724244e6-cf1d-4a66-baf4-9f9eacd54be5'})
            MERGE (increment:IncrementId {nodeName: 'Profile'})
                ON CREATE SET increment.id = 2
                ON MATCH SET increment.id = increment.id + 1
            CREATE (profile:Profile {
                profileId: (increment.id),
                profileType: 'MoneyhubProfile',
                profileName: identity.name,
                brand: identity.defaultBrand,
                fullCatalogAccess: true,
                roles: ['accounting'],
                uuid: apoc.create.uuid(),
                createdAt: datetime(),
                lastModifiedAt: datetime(),
                createdBy: 'database/WAR-3391_vendor_star_access:4',
                lastModifiedBy: 'database/WAR-3391_vendor_star_access:4'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3391_vendor_star_access:5" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: '3eb9defa-892a-4bbf-a669-20981a42665e'})
            MERGE (increment:IncrementId {nodeName: 'Profile'})
                ON CREATE SET increment.id = 2
                ON MATCH SET increment.id = increment.id + 1
            CREATE (profile:Profile {
                profileId: (increment.id),
                profileType: 'MoneyhubProfile',
                profileName: identity.name,
                brand: identity.defaultBrand,
                fullCatalogAccess: true,
                roles: ['accounting'],
                uuid: apoc.create.uuid(),
                createdAt: datetime(),
                lastModifiedAt: datetime(),
                createdBy: 'database/WAR-3391_vendor_star_access:5',
                lastModifiedBy: 'database/WAR-3391_vendor_star_access:5'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3391_vendor_star_access:6" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: '7ac31e15-602b-48d1-b672-b32a52f11f67'})
            MERGE (increment:IncrementId {nodeName: 'Profile'})
                ON CREATE SET increment.id = 2
                ON MATCH SET increment.id = increment.id + 1
            CREATE (profile:Profile {
                profileId: (increment.id),
                profileType: 'MoneyhubProfile',
                profileName: identity.name,
                brand: identity.defaultBrand,
                fullCatalogAccess: true,
                roles: ['accounting'],
                uuid: apoc.create.uuid(),
                createdAt: datetime(),
                lastModifiedAt: datetime(),
                createdBy: 'database/WAR-3391_vendor_star_access:6',
                lastModifiedBy: 'database/WAR-3391_vendor_star_access:6'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

</databaseChangeLog>
