<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.liquigraph.org/schema/1.0/liquigraph.xsd">
    <changeset id="PLATFORM-2436_Fix-identities-without-ids:1" author="npatel" run-on-change="true">
        <query>
            MATCH (i:Identity)
            WHERE NOT (i)-[:HAS_PROFILE]->(:Profile {profileType: "SettingsProfile"})
            WITH i
            
            MATCH (inc:IncrementId {nodeName: 'Profile'})
            CREATE (pNew:Profile {profileType: "SettingsProfile" , profileId: inc.id})
                SET inc.id = inc.id +1, pNew.profileName = i.name, pNew.updatedOn = datetime(), pNew.updatedBy = 'PLATFORM-2496'   
            CREATE (i)-[:HAS_PROFILE]->(pNew)
            WITH i, pNew
            
            MATCH (i)-[:HAS_PROFILE]->(lp:Profile {profileType: "LabelProfile"})-[:HAS_ACCESS_TO]->(r)
            WHERE 'administrator' IN lp.roles
            CREATE (pNew)-[:HAS_ADMIN_ACCESS_TO]->(r)
            ;
        </query>
    </changeset>
</changelog>
