<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:/var/app/InputFileSchema.xsd">
    <changeset id="DS-6314_soft_delete_redundant_represents_video_relationships:1" author="mmurha" run-always="true">
        <precondition>
            <sqlquery>
                <![CDATA[
                    SELECT id AS GSR_ID
                    FROM FACTS.PROD.GLOBAL_SOUND_RECORDING;
                ]]>
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH (v:Video:YouTube)<-[r:REPRESENTS_VIDEO]-(gsr:GlobalSoundRecording {id: event.GSR_ID})
                WHERE v.isrc <> gsr.isrc
                WITH v, gsr, r
                    MATCH (v)<-[:REPRESENTS_VIDEO]-(sgsr:GlobalSoundRecording)
                    WHERE v.isrc = sgsr.isrc
                    WITH DISTINCT r
                        CALL apoc.refactor.setType(r, 'DELETED_REPRESENTS_VIDEO')
                        YIELD input, output
                        SET output.deletedAt = datetime(),
                            output.deletedBy = 'DS-6314_soft_delete_redundant_represents_video_relationships:1'
            ]]>
        </cypherquery>
    </changeset>
</changelog>