<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://www.liquigraph.org/schema/1.0/liquigraph.xsd">
    <changeset id="PUB-140-backfill-createdBy-and-modifiedBy.xml:1" author="sgusev">
        <!-- 1: Update PublishingComposition.createdBy property -->
        <query>
            <![CDATA[
            MATCH (pc:PublishingComposition)
            MATCH (p:Profile {profileType:'PublishingProfile', profileId: toInteger(pc.createdBy)})<-[:HAS_PROFILE]-(i:Identity)
            WHERE apoc.meta.type(pc.createdBy) = 'INTEGER' OR (apoc.meta.type(pc.createdBy) = 'STRING' and length(pc.createdBy) > 0 and length(pc.createdBy) < 10)
            SET pc.createdBy = i.id
            RETURN pc.id
            ]]>
        </query>
    </changeset>
    <changeset id="PUB-140-backfill-createdBy-and-modifiedBy.xml:2" author="sgusev">
        <!-- 2: Rename PublishingComposition.updatedBy to PublishingComposition.modifiedBy -->
        <query>
            MATCH (pc:PublishingComposition)
            WHERE EXISTS (pc.updatedBy)
            SET pc.modifiedBy = pc.updatedBy
            REMOVE pc.updatedBy
            return pc.id
        </query>
    </changeset>
    <changeset id="PUB-140-backfill-createdBy-and-modifiedBy.xml:3" author="sgusev">
        <!-- 3: Update PublishingComposition.modifiedBy property -->
        <query>
            <![CDATA[
            MATCH (pc:PublishingComposition)
            MATCH (p:Profile {profileType:'PublishingProfile', profileId: toInteger(pc.modifiedBy)})<-[:HAS_PROFILE]-(i:Identity)
            WHERE apoc.meta.type(pc.modifiedBy) = 'INTEGER' OR (apoc.meta.type(pc.modifiedBy) = 'STRING' and length(pc.modifiedBy) > 0 and length(pc.modifiedBy) < 10)
            SET pc.modifiedBy = i.id
            RETURN pc.id
            ]]>
        </query>
    </changeset>
    <changeset id="PUB-140-backfill-createdBy-and-modifiedBy.xml:4" author="sgusev">
        <!-- 4: Update PublishingAgreement.createdBy property -->
        <query>
            <![CDATA[
            MATCH (pa:PublishingAgreement)
            MATCH (p:Profile {profileType:'PublishingProfile', profileId: toInteger(pa.createdBy)})<-[:HAS_PROFILE]-(i:Identity)
            WHERE apoc.meta.type(pa.createdBy) = 'INTEGER' OR (apoc.meta.type(pa.createdBy) = 'STRING' and length(pa.createdBy) > 0 and length(pa.createdBy) < 10)
            SET pa.createdBy = i.id
            RETURN pa.id
            ]]>
        </query>
    </changeset>
    <changeset id="PUB-140-backfill-createdBy-and-modifiedBy.xml:5" author="sgusev">
        <!-- 5: Update PublishingPublisher.createdBy property -->
        <query>
            <![CDATA[
            MATCH (pp:PublishingPublisher)
            MATCH (p:Profile {profileType:'PublishingProfile', profileId: toInteger(pp.createdBy)})<-[:HAS_PROFILE]-(i:Identity)
            WHERE apoc.meta.type(pp.createdBy) = 'INTEGER' OR (apoc.meta.type(pp.createdBy) = 'STRING' and length(pp.createdBy) > 0 and length(pp.createdBy) < 10)
            SET pp.createdBy = i.id
            RETURN pp.id
            ]]>
        </query>
    </changeset>
    <changeset id="PUB-140-backfill-createdBy-and-modifiedBy.xml:6" author="sgusev">
        <!-- 6: Update PublishingPublisher.modifiedBy property -->
        <query>
            <![CDATA[
            MATCH (pp:PublishingPublisher)
            MATCH (p:Profile {profileType:'PublishingProfile', profileId: toInteger(pp.modifiedBy)})<-[:HAS_PROFILE]-(i:Identity)
            WHERE apoc.meta.type(pp.modifiedBy) = 'INTEGER' OR (apoc.meta.type(pp.modifiedBy) = 'STRING' and length(pp.modifiedBy) > 0 and length(pp.modifiedBy) < 10)
            SET pp.modifiedBy = i.id
            RETURN pp.id
            ]]>
        </query>
    </changeset>
    <changeset id="PUB-140-backfill-createdBy-and-modifiedBy.xml:7" author="sgusev">
        <!-- 7: Update PublishingSongWriter.createdBy property -->
        <query>
            <![CDATA[
            MATCH (psw:PublishingSongWriter)
            MATCH (p:Profile {profileType:'PublishingProfile', profileId: toInteger(psw.createdBy)})<-[:HAS_PROFILE]-(i:Identity)
            WHERE apoc.meta.type(psw.createdBy) = 'INTEGER' OR (apoc.meta.type(psw.createdBy) = 'STRING' and length(psw.createdBy) > 0 and length(psw.createdBy) < 10)
            SET psw.createdBy = i.id
            RETURN psw.id
            ]]>
        </query>
    </changeset>
    <changeset id="PUB-140-backfill-createdBy-and-modifiedBy.xml:8" author="sgusev">
        <!-- 8: Update PublishingSongWriter.modifiedBy property -->
        <query>
            <![CDATA[
            MATCH (psw:PublishingSongWriter)
            MATCH (p:Profile {profileType:'PublishingProfile', profileId: toInteger(psw.modifiedBy)})<-[:HAS_PROFILE]-(i:Identity)
            WHERE apoc.meta.type(psw.modifiedBy) = 'INTEGER' OR (apoc.meta.type(psw.modifiedBy) = 'STRING' and length(psw.modifiedBy) > 0 and length(psw.modifiedBy) < 10)
            SET psw.modifiedBy = i.id
            RETURN psw.id
            ]]>
        </query>
    </changeset>
</changelog>
