<?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="IN-10949_backfill_spotifyid_on_labelparticipants:1"
     author="borisuvarov"
     run-always="true"
     topic="stream.storeAPIRequest.spotify.split">
        <precondition>
            <sqlquery>
                <![CDATA[
                    WITH backfill_data AS (
                        SELECT
                            DISTINCT
                                op.id AS id,
                                op.upc AS upc,
                                lp.vendor_id AS vendor_id,
                                lp.subaccount_id AS subaccount_id
                        FROM FACTS.PROD.ORCHARD_PRODUCT op
                        INNER JOIN FACTS.PROD.LABEL_PARTICIPANT_PARTICIPATED_IN_ORCHARD_PRODUCT lp_pi_op
                            ON op.id = lp_pi_op.product_id
                        INNER JOIN FACTS.PROD.LABEL_PARTICIPANT lp
                            ON lp_pi_op.label_participant_id = lp.id
                        WHERE lp_pi_op.participated_as IN ('performer', 'featuring', 'remixer')
                            AND lp.spotify_id IS NULL
                        ORDER BY 1, 2, 3, 4
                    )
                    SELECT
                        OBJECT_CONSTRUCT(
                            'api_request', OBJECT_CONSTRUCT(
                                'store', 'SPOTIFY',
                                'type', 'SEARCH_ALBUM_BY_UPC'
                            ),
                            'payload', OBJECT_CONSTRUCT(
                                'product_id', id,
                                'upc', upc,
                                'vendor_id', vendor_id,
                                'subaccount_id', subaccount_id
                            )
                        ) AS VALUE
                    FROM backfill_data
                ]]>
            </sqlquery>
        </precondition>
    </changeset>
</changelog>
