-- 关系指数表新增任务统计字段（2026-03-31）
-- C: 历史总计字段

BEGIN;

ALTER TABLE dws.dws_member_assistant_relation_index
    ADD COLUMN IF NOT EXISTS recall_created_total      INT NOT NULL DEFAULT 0,
    ADD COLUMN IF NOT EXISTS recall_completed_total     INT NOT NULL DEFAULT 0,
    ADD COLUMN IF NOT EXISTS follow_up_created_total    INT NOT NULL DEFAULT 0,
    ADD COLUMN IF NOT EXISTS follow_up_completed_total  INT NOT NULL DEFAULT 0,
    ADD COLUMN IF NOT EXISTS total_created              INT NOT NULL DEFAULT 0,
    ADD COLUMN IF NOT EXISTS total_completed            INT NOT NULL DEFAULT 0;

COMMENT ON COLUMN dws.dws_member_assistant_relation_index.recall_created_total IS '历史累计召回任务创建数';
COMMENT ON COLUMN dws.dws_member_assistant_relation_index.recall_completed_total IS '历史累计召回任务完成数';
COMMENT ON COLUMN dws.dws_member_assistant_relation_index.follow_up_created_total IS '历史累计回访任务创建数';
COMMENT ON COLUMN dws.dws_member_assistant_relation_index.follow_up_completed_total IS '历史累计回访任务完成数';
COMMENT ON COLUMN dws.dws_member_assistant_relation_index.total_created IS '历史累计任务创建总数';
COMMENT ON COLUMN dws.dws_member_assistant_relation_index.total_completed IS '历史累计任务完成总数';

COMMIT;

-- ROLLBACK:
-- ALTER TABLE dws.dws_member_assistant_relation_index
--     DROP COLUMN IF EXISTS recall_created_total,
--     DROP COLUMN IF EXISTS recall_completed_total,
--     DROP COLUMN IF EXISTS follow_up_created_total,
--     DROP COLUMN IF EXISTS follow_up_completed_total,
--     DROP COLUMN IF EXISTS total_created,
--     DROP COLUMN IF EXISTS total_completed;
