<?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-2994_vendor_star_access:1" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (:Identity {email: 'mkhimka@sonymusic-pde.com'})
                -[:HAS_PROFILE]->(profile:Profile {profileType: 'MoneyhubProfile'})
                -[relationship:DELETED_HAS_ACCESS_TO]->(:Vendor {id: '*'})
            DELETE relationship
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO {
                createdAt: datetime(),
                createdBy: 'database/WAR-2994_vendor_star_access:1',
                lastModifiedAt: datetime(),
                lastModifiedBy: 'database/WAR-2994_vendor_star_access:1'
            }]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-2994_vendor_star_access:2" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (:Identity {email: 'samiia.zenkevich.ext@sonymusic-pde.com'})
                -[:HAS_PROFILE]->(profile:Profile {profileType: 'MoneyhubProfile'})
                -[relationship:DELETED_HAS_ACCESS_TO]->(:Vendor {id: '*'})
            DELETE relationship
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO {
                createdAt: datetime(),
                createdBy: 'database/WAR-2994_vendor_star_access:2',
                lastModifiedAt: datetime(),
                lastModifiedBy: 'database/WAR-2994_vendor_star_access:2'
            }]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-2994_vendor_star_access:3" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (:Identity {email: 'daniel.jimenez@sonymusic-pde.com'})
                -[:HAS_PROFILE]->(profile:Profile {profileType: 'MoneyhubProfile'})
                -[relationship:DELETED_HAS_ACCESS_TO]->(:Vendor {id: '*'})
            DELETE relationship
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO {
                createdAt: datetime(),
                createdBy: 'database/WAR-2994_vendor_star_access:3',
                lastModifiedAt: datetime(),
                lastModifiedBy: 'database/WAR-2994_vendor_star_access:3'
            }]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-2994_vendor_star_access:4" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {email: 'margarita.timashova@sonymusic-pde.com'})
            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-2994_vendor_star_access:4',
                lastModifiedBy: 'database/WAR-2994_vendor_star_access:4'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO {
                createdAt: datetime(),
                createdBy: 'database/WAR-2994_vendor_star_access:4',
                lastModifiedAt: datetime(),
                lastModifiedBy: 'database/WAR-2994_vendor_star_access:4'
            }]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-2994_vendor_star_access:5" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {email: 'roy.patterson@sonymusic-pde.com'})
            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-2994_vendor_star_access:5',
                lastModifiedBy: 'database/WAR-2994_vendor_star_access:5'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO {
                createdAt: datetime(),
                createdBy: 'database/WAR-2994_vendor_star_access:5',
                lastModifiedAt: datetime(),
                lastModifiedBy: 'database/WAR-2994_vendor_star_access:5'
            }]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-2994_vendor_star_access:6" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {email: 'bethany.marshall@awal.com'})
            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-2994_vendor_star_access:6',
                lastModifiedBy: 'database/WAR-2994_vendor_star_access:6'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO {
                createdAt: datetime(),
                createdBy: 'database/WAR-2994_vendor_star_access:6',
                lastModifiedAt: datetime(),
                lastModifiedBy: 'database/WAR-2994_vendor_star_access:6'
            }]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

</databaseChangeLog>
