﻿-- 灏嗘柊鐨?ODS 浠诲姟娉ㄥ唽鍒?etl_admin.etl_task锛堟牴鎹渶瑕佹浛鎹?store_id锛?
-- 浣跨敤鏂瑰紡锛堢ず渚嬶級锛?
--   psql "$PG_DSN" -f etl_billiards/database/seed_ods_tasks.sql
-- 鎴栬€呭湪 psql 涓墽琛屾湰鏂囦欢鍐呭銆?

WITH target_store AS (
    SELECT 2790685415443269::bigint AS store_id  -- TODO: 鏇挎崲涓哄疄闄?store_id
),
task_codes AS (
    SELECT unnest(ARRAY[
        'assistant_accounts_masterS',
        'assistant_service_records',
        'assistant_cancellation_records',
        'goods_stock_movements',
        'ODS_INVENTORY_STOCK',
        'ODS_PACKAGE',
        'ODS_GROUP_BUY_REDEMPTION',
        'ODS_MEMBER',
        'ODS_MEMBER_BALANCE',
        'member_stored_value_cards',
        'ODS_PAYMENT',
        'ODS_REFUND',
        'platform_coupon_redemption_records',
        'recharge_settlements',
        'ODS_TABLES',
        'ODS_GOODS_CATEGORY',
        'ODS_STORE_GOODS',
        'table_fee_discount_records',
        'ODS_TENANT_GOODS',
        'ODS_SETTLEMENT_TICKET',
        'settlement_records',
        'INIT_ODS_SCHEMA'
    ]) AS task_code
)
INSERT INTO etl_admin.etl_task (task_code, store_id, enabled)
SELECT t.task_code, s.store_id, TRUE
FROM task_codes t CROSS JOIN target_store s
ON CONFLICT (task_code, store_id) DO UPDATE
SET enabled = EXCLUDED.enabled;


