-- ============================================================
-- Migration: Add RECURRENCE_RULE_ID to TTM_CLIENT_TASK_MAPPING and TTM_TASK
-- Frequency/recurrence is now selected at task-mapping time (not template creation)
-- ============================================================

-- Add RECURRENCE_RULE_ID to TTM_CLIENT_TASK_MAPPING (admin selects frequency at mapping time)
ALTER TABLE TTM_CLIENT_TASK_MAPPING
  ADD COLUMN RECURRENCE_RULE_ID int DEFAULT NULL
    COMMENT 'FK -> TTM_RECURRENCE_RULE_MASTER.ID — selected by admin at mapping time'
  AFTER ENGAGEMENT_TYPE_ID;

-- Add RECURRENCE_RULE_ID to TTM_TASK (carried from mapping when task is created)
ALTER TABLE TTM_TASK
  ADD COLUMN RECURRENCE_RULE_ID int DEFAULT NULL
    COMMENT 'FK -> TTM_RECURRENCE_RULE_MASTER.ID — from client-task mapping'
  AFTER CONTRACT_ID;
