<?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-10126_Backfill_channels_from_snowflake_to_neo4js:1" author="oefanova" neo4j-server="music-graph" run-always="true">
        <precondition>
            <sqlquery>
                <![CDATA[
SELECT DISTINCT
    channel_id,
    channel_display_name,
    description,
    TO_VARCHAR(published_at, 'YYYY-MM-DD"T"HH24:MI:SS') as published_at,
    subscriber_count,
    thumbnail_url,
    view_count,
    video_count,
    artist_id,
    label_id,
    subaccount_id,
    channel_owner
FROM dev_engineering.oefanova.temp_youtube_neo4j_channel
                ]]>
            </sqlquery>
        </precondition>
        <cypherquery>
            <![CDATA[
MERGE (c:Channel:YouTube {channelId: event.CHANNEL_ID})
    ON CREATE SET
        c.id = randomUUID(),
        c.name = event.CHANNEL_DISPLAY_NAME,
        c.description = event.DESCRIPTION,
        c.publishedAt = datetime(event.PUBLISHED_AT),
        c.subscriberCount = event.SUBSCRIBER_COUNT,
        c.thumbnailUrl = event.THUMBNAIL_URL,
        c.viewCount = event.VIEW_COUNT,
        c.videoCount = event.VIDEO_COUNT,
        c.artistId = event.ARTIST_ID,
        c.labelId = event.LABEL_ID,
        c.subaccountId = event.SUBACCOUNT_ID,
        c.channelOwner = event.CHANNEL_OWNER,
        c.createdAt = datetime(),
        c.createdBy = 'DS-10126_Backfill_channels_from_snowflake_to_neo4j',
        c.modifiedAt = datetime(),
        c.modifiedBy = 'DS-10126_Backfill_channels_from_snowflake_to_neo4j'
    ON MATCH SET
        c.name = event.CHANNEL_DISPLAY_NAME,
        c.publishedAt = datetime(event.PUBLISHED_AT),
        c.subscriberCount = event.SUBSCRIBER_COUNT,
        c.thumbnailUrl = event.THUMBNAIL_URL,
        c.viewCount = event.VIEW_COUNT,
        c.videoCount = event.VIDEO_COUNT,
        c.artistId = event.ARTIST_ID,
        c.labelId = event.LABEL_ID,
        c.subaccountId = event.SUBACCOUNT_ID,
        c.channelOwner = event.CHANNEL_OWNER,
        c.modifiedAt = datetime(),
        c.modifiedBy = 'DS-10126_Backfill_channels_from_snowflake_to_neo4j'
            ]]>
        </cypherquery>
    </changeset>
</changelog>
