/*
12.03.2025, TSC
*/
USE [dba_reporting]

SELECT * from SYM_NODE
--SELECT * FROM SYM_NODE_GROUP
SELECT * FROM SYM_NODE_GROUP_LINK
 
SELECT * FROM sym_channel
SELECT * FROM SYM_ROUTER 
SELECT * FROM SYM_TRIGGER ORDER BY [channel_id]
SELECT * FROM SYM_TRIGGER_ROUTER ORDER BY [router_id]

--SELECT * FROM [dbo].[sym_outgoing_batch]
RETURN

--set push to cloud, pull to onprem
UPDATE [dbo].[sym_node_group_link] SET [data_event_action]='W' WHERE [source_node_group_id]='cloud' 
UPDATE [dbo].[sym_node_group_link] SET [data_event_action]='P' WHERE [source_node_group_id]='onprem'

--set router target schemas. sl2007 is the target on cloud, sl2007_azure is the target on prem
UPDATE dbo.[sym_router] SET [target_catalog_name]='sl2007', [target_schema_name]='dbo' WHERE [router_id] = 'onprem to cloud'
UPDATE dbo.[sym_router] SET [target_catalog_name]='sl2007_azure', [target_schema_name]='dbo' WHERE [router_id] = 'cloud to onprem'

--create a single channel for all tables to push to cloud
INSERT INTO dbo.SYM_CHANNEL (channel_id, processing_order, max_batch_size, max_batch_to_send,extract_period_millis, batch_algorithm, enabled, description,data_loader_type)
SELECT channel_id, processing_order, max_batch_size, max_batch_to_send,extract_period_millis, batch_algorithm, enabled, description,data_loader_type
FROM(
    VALUES ('sl2007_push', 10, 1000, 10, 0, 'default', 1, 'sl2007 data to push to cloud','bulk')
    ,('sl2007_pull',20,1000,10,0,'default',1,'sl2007 push from cloud to on-prem','bulk')
)x(channel_id, processing_order, max_batch_size, max_batch_to_send,extract_period_millis, batch_algorithm, enabled, description,data_loader_type)
WHERE NOT EXISTS(SELECT 1 FROM [dbo].[sym_channel] c WHERE c.[channel_id] = x.[channel_id]);

--Add tables triggers for push
--DELETE FROM [dbo].[sym_trigger_router] WHERE router_id='onprem to cloud'
--DELETE FROM [dbo].[sym_trigger] WHERE channel_id='sl2007_push'
INSERT INTO dbo.SYM_TRIGGER (trigger_id, source_table_name,channel_id, last_update_time, create_time, source_catalog_name, source_schema_name, excluded_column_names)
SELECT trigger_id, source_table_name,channel_id, last_update_time, create_time, source_catalog_name, source_schema_name,excluded_column_names
FROM (
    VALUES 
     ('push_PARTNER_MUTATION', 'PARTNER_MUTATION', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PARTNER', 'PARTNER', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PACKPARTNER_MUTATION', 'PACKPARTNER_MUTATION', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_ATCDESCR', 'ATCDESCR', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PREPARATION_IGNORE', 'PREPARATION_IGNORE', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PACK_IGNORE', 'PACK_IGNORE', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PACK_NEW', 'PACK_NEW', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PREPARATION_NEW', 'PREPARATION_NEW', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PACK_MUTATION', 'PACK_MUTATION', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PREPARATION_MUTATION', 'PREPARATION_MUTATION', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PREPARATION', 'PREPARATION', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PACK', 'PACK', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_SUBSTANCE', 'SUBSTANCE', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PREPSUB', 'PREPSUB', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
    ,('push_PrepGenGroup', 'PrepGenGroup', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',null)
    ,('push_COM_CHAIN', 'COM_CHAIN', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',null)
    ,('push_ITDESCR', 'ITDESCR', 'sl2007_push', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','time_stamp')
)x(trigger_id, source_table_name,channel_id, last_update_time, create_time,source_catalog_name, source_schema_name,excluded_column_names)
WHERE NOT EXISTS (SELECT 1 FROM [dbo].[sym_trigger] c WHERE c.[trigger_id]=x.[trigger_id] AND c.[channel_id]=x.[channel_id]);

--trigger router for push
INSERT INTO [dbo].[sym_trigger_router] ([trigger_id],[router_id],[enabled],[initial_load_order],[create_time],[last_update_by],[last_update_time],[description],[data_refresh_type])
SELECT 
    [trigger_id]
    ,'onprem to cloud' AS [router_id]
    ,1 AS [enabled]
    ,1 AS [initial_load_order]
    ,CURRENT_TIMESTAMP AS [create_time]
    ,'TSC' AS [last_update_by]
    ,CURRENT_TIMESTAMP AS [last_update_time]
    ,'Push of data to cloud' AS [description]
    ,'auto' AS [data_refresh_type]
FROM [dbo].[sym_trigger] x
WHERE x.[channel_id]='sl2007_push'
AND NOT EXISTS (SELECT 1 FROM [dbo].[sym_trigger_router] c WHERE c.[trigger_id]=x.[trigger_id] AND c.[router_id]='onprem to cloud')


--Add tables triggers for pull
/*
to create the VALUES below, from the db to sync run the following query and take the "out" column values:

select
    t.name,
    STUFF(CONVERT(VARCHAR(MAX),f.lst),1,1,'') AS lst,
    '       ,('''+t.name+''', '''+t.name+''', ''sl2007_pull'', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,''sl2007'',''dbo'','+COALESCE(''''+STUFF(CONVERT(VARCHAR(MAX),f.lst),1,1,'')+'''','NULL')+')' as out
from sys.tables t
    OUTER APPLY(
        SELECT ','+[c].[COLUMN_NAME]
        FROM [INFORMATION_SCHEMA].[COLUMNS] c
        WHERE c.[TABLE_NAME] = [t].[name]
        AND [c].[DATA_TYPE]='timestamp'
        FOR XML PATH(''),TYPE
    ) f(lst)
ORDER BY t.name 
*/
--DELETE FROM [dbo].[sym_trigger_router] WHERE router_id='cloud to onprem'
--DELETE FROM [dbo].[sym_trigger] WHERE channel_id='sl2007_pull'
INSERT INTO dbo.SYM_TRIGGER (trigger_id, source_table_name,channel_id, last_update_time, create_time, source_catalog_name, source_schema_name, excluded_column_names)
SELECT trigger_id, source_table_name,channel_id, last_update_time, create_time, source_catalog_name, source_schema_name,excluded_column_names
FROM (
    VALUES 
       ('pull_ATCDESCR', 'ATCDESCR', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_COM_CHAIN', 'COM_CHAIN', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_Gamme', 'Gamme', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_GENERICBASEDATA_FROM_ARTIKEL_SUPERSET', 'GENERICBASEDATA_FROM_ARTIKEL_SUPERSET', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_GENERICBASEDATA_FROM_ARTIKEL_SUPERSET_eme7w006', 'GENERICBASEDATA_FROM_ARTIKEL_SUPERSET_eme7w006', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_IMSData', 'IMSData', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_IMSData_Add', 'IMSData_Add', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_IMSData_Archiv', 'IMSData_Archiv', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_IMSData_ExcelImport', 'IMSData_ExcelImport', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_ITDESCR', 'ITDESCR', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_ITLIMIT', 'ITLIMIT', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_LIMITATION', 'LIMITATION', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_LIMITATION_HISTORY', 'LIMITATION_HISTORY', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_LimitationChangeType', 'LimitationChangeType', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','Time_Stamp')
       ,('pull_LOASPEZ', 'LOASPEZ', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_Logging', 'Logging', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_NATION', 'NATION', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_ORG_GEN_UMSATZ', 'ORG_GEN_UMSATZ', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_OrgGenManualGrenzwert', 'OrgGenManualGrenzwert', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_ORIGINAL_FREIKAUF', 'ORIGINAL_FREIKAUF', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_OriginalGenericMapping', 'OriginalGenericMapping', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_PACK', 'PACK', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PACK_IGNORE', 'PACK_IGNORE', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PACK_LIMPTS', 'PACK_LIMPTS', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PACK_MUTATION', 'PACK_MUTATION', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PACK_NEW', 'PACK_NEW', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PACKPARTNER', 'PACKPARTNER', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PACKPARTNER_IGNORE', 'PACKPARTNER_IGNORE', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PACKPARTNER_MUTATION', 'PACKPARTNER_MUTATION', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PACKPRICE', 'PACKPRICE', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PARTNER', 'PARTNER', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PARTNER_IGNORE', 'PARTNER_IGNORE', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PARTNER_MUTATION', 'PARTNER_MUTATION', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PIMPORT', 'PIMPORT', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_PreiseNeu', 'PreiseNeu', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_PREPARATION', 'PREPARATION', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PREPARATION_IGNORE', 'PREPARATION_IGNORE', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PREPARATION_MUTATION', 'PREPARATION_MUTATION', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PREPARATION_NAME', 'PREPARATION_NAME', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_PREPARATION_NAME_BOOK', 'PREPARATION_NAME_BOOK', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_PREPARATION_NAME_save_vorGammendef20120404', 'PREPARATION_NAME_save_vorGammendef20120404', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_PREPARATION_NEW', 'PREPARATION_NEW', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PREPARATIONTASK', 'PREPARATIONTASK', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PrepGenGroup', 'PrepGenGroup', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_PREPIT', 'PREPIT', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PREPPACKLIMIT', 'PREPPACKLIMIT', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PREPPACKLIMIT_GGML', 'PREPPACKLIMIT_GGML', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PREPPACKSTATUS', 'PREPPACKSTATUS', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PREPPACKSTATUS_GGML', 'PREPPACKSTATUS_GGML', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PREPSUB', 'PREPSUB', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PRICECHANGETYPE', 'PRICECHANGETYPE', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PRICETYPE', 'PRICETYPE', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PUBLICATION', 'PUBLICATION', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PUBLICATION_STATUS', 'PUBLICATION_STATUS', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_PublicationRun', 'PublicationRun', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_RECIDKORR', 'RECIDKORR', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_SL_AUFNSTRCH', 'SL_AUFNSTRCH', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_STATUSTYPE_GGML', 'STATUSTYPE_GGML', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_STATUSTYPE_SL', 'STATUSTYPE_SL', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_SUBSTANCE', 'SUBSTANCE', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_TEMP_BIG_APV', 'TEMP_BIG_APV', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_temp_Modal_Formstaerke', 'temp_Modal_Formstaerke', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_TempAPV20131101', 'TempAPV20131101', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_TempImport', 'TempImport', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_TempUmsatz3J', 'TempUmsatz3J', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_TempUmsatzGamme', 'TempUmsatzGamme', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_TMP_ArtikelVerknuepfungen', 'TMP_ArtikelVerknuepfungen', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_TMP_VertriebsanteilGruppe', 'TMP_VertriebsanteilGruppe', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_Ueberpruefungseinheit', 'Ueberpruefungseinheit', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_VARIA', 'VARIA', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo','TIME_STAMP')
       ,('pull_VERLIST', 'VERLIST', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
       ,('pull_VertriebsanteilGruppe', 'VertriebsanteilGruppe', 'sl2007_pull', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'sl2007','dbo',NULL)
)x(trigger_id, source_table_name,channel_id, last_update_time, create_time,source_catalog_name, source_schema_name,excluded_column_names)
WHERE NOT EXISTS (SELECT 1 FROM [dbo].[sym_trigger] c WHERE c.[trigger_id]=x.[trigger_id] AND c.[channel_id]=x.[channel_id]);

--trigger router for pull

INSERT INTO [dbo].[sym_trigger_router] ([trigger_id],[router_id],[enabled],[initial_load_order],[create_time],[last_update_by],[last_update_time],[description],[data_refresh_type])
SELECT 
    [trigger_id]
    ,'cloud to onprem' AS [router_id]
    ,1 AS [enabled]
    ,1 AS [initial_load_order]
    ,CURRENT_TIMESTAMP AS [create_time]
    ,'TSC' AS [last_update_by]
    ,CURRENT_TIMESTAMP AS [last_update_time]
    ,'Pull of data from cloud' AS [description]
    ,'auto' AS [data_refresh_type]
FROM [dbo].[sym_trigger] x
WHERE x.[channel_id]='sl2007_pull'
AND NOT EXISTS (SELECT 1 FROM [dbo].[sym_trigger_router] c WHERE c.[trigger_id]=x.[trigger_id] AND c.[router_id]='cloud to onprem')
