-- CHANGE 2026-02-15 | 修复 schema 引用：etl_admin → meta（对齐新库 etl_feiqiu 六层架构）
-- Seed scheduler-compatible tasks into meta.etl_task.
--
-- Notes:
-- - These task_code values must match orchestration/task_registry.py.
-- - ODS_* tasks are intentionally excluded here because they don't follow the
--   BaseTask(cursor_data) scheduler interface in this repo version.
--
-- Usage (example):
--   psql "%PG_DSN%" -f etl_billiards/database/seed_scheduler_tasks.sql
--
WITH target_store AS (
    SELECT 2790685415443269::bigint AS store_id  -- TODO: replace with your store_id
),
task_codes AS (
    SELECT unnest(ARRAY[
        'ASSISTANT_ABOLISH',
        'ASSISTANTS',
        'COUPON_USAGE',
        'CHECK_CUTOFF',
        'DWD_LOAD_FROM_ODS',
        'DWD_QUALITY_CHECK',
        'INIT_DWD_SCHEMA',
        'INIT_DWS_SCHEMA',
        'INIT_ODS_SCHEMA',
        'INVENTORY_CHANGE',
        'LEDGER',
        'MANUAL_INGEST',
        'MEMBERS',
        'MEMBERS_DWD',
        'ODS_JSON_ARCHIVE',
        'ORDERS',
        'PACKAGES_DEF',
        'PAYMENTS',
        'PAYMENTS_DWD',
        'PRODUCTS',
        'REFUNDS',
        'TABLE_DISCOUNT',
        'TABLES',
        'TICKET_DWD',
        'TOPUPS',
        'DWS_BUILD_ORDER_SUMMARY',
        'DWS_WINBACK_INDEX',
        'DWS_NEWCONV_INDEX',
        'DWS_RELATION_INDEX',
        'DWS_ML_MANUAL_IMPORT'
    ]) AS task_code
)
INSERT INTO meta.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,
    updated_at = now();
