<?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="SR-179_remove_lsr_wo_track_rels:1" author="gaguirre" run-always="true">
        <precondition>
            <sqlquery>
                <![CDATA[
                    SELECT 
                        distinct lsr.id
                    FROM FACTS.PROD.LABEL_SOUND_RECORDING AS lsr
                    LEFT JOIN FACTS.PROD.ORCHARD_TRACK_IS_PLACEMENT_OF_LABEL_SOUND_RECORDING AS otipolsr
                        ON otipolsr.LABEL_SOUND_RECORDING_ID = lsr.id
                    WHERE otipolsr.track_id IS NULL
                ]]>
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
                MATCH(lsr:LabelSoundRecording {id: event.ID})
                WHERE NOT (lsr)<-[:IS_PLACEMENT_OF]-(:Track:Orchard)
                DETACH DELETE lsr
            ]]>
        </cypherquery>
    </changeset>
</changelog>
