<?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="KDH-597_backfill_os_content_search_project_id:1"
         author="npatel"
         run-always="true"
         topic="event.backup.prod.etl.projects"
         snowflake-account="orchard"
     >
    <!--  send 4704787 rows to the topic. -->
        <precondition>
            <sqlquery>
                <![CDATA[
                   with all_data as (
                       SELECT
                            distinct p.project_id,
                            v.vendor_uuid AS vendorUUID,
                            s.subaccount_uuid AS subaccountUUID,
                            cb.uuid AS companyBrandUUID,
                            pc.uuid AS parentCompanyUUID
                        FROM orchard_app_reporting_v2.art_relations_prod_art_relations.project p
                        INNER JOIN orchard_app_reporting_v2.art_relations_prod_art_relations.vendor v
                                ON v.vendor_id = p.vendor_id
                        INNER JOIN FACTS.PROD.COMPANY_BRAND cb
                            ON cb.company_brand_id = v.company_brand_id
                        INNER JOIN FACTS.PROD.COMPANY_BRAND_BELONGS_TO_PARENT_COMPANY bt ON cb.uuid = bt.company_brand_uuid
                        INNER JOIN FACTS.PROD.PARENT_COMPANY pc  ON bt.parent_company_uuid = pc.uuid
                        LEFT JOIN
                          orchard_app_reporting_v2.art_relations_prod_art_relations.subaccount s ON p.subaccount_id = s.subaccount_id
                    )
                    select 
                        TO_NUMBER(all_data.project_id) AS KEY,
                        OBJECT_CONSTRUCT(
                            'project_id', TO_NUMBER(all_data.project_id),
                            'vendorUUID', TO_VARCHAR(all_data.vendorUUID),
                            'subaccountUUID', TO_VARCHAR(all_data.subaccountUUID),
                            'companyBrandUUID', TO_VARCHAR(all_data.companyBrandUUID),
                            'parentCompanyUUID', TO_VARCHAR(all_data.parentCompanyUUID)
                        ) AS VALUE
                    from all_data 
                ]]>
            </sqlquery>
        </precondition>
    </changeset>
    
</changelog>
