-- WhatsApp: records which Meta-approved template started a conversation (the "New Conversation"
-- flow) — null for every reply/free-text message and every inbound message.
-- Idempotent — safe to re-run.
-- Deploy: mysql -u <user> -p < db/aggie_add_whatsapp_template_name.sql

USE `stacie_Aggie_v1.0`;

SET @col_exists = (SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'fact_whatsapp_message' AND COLUMN_NAME = 'template_name');
SET @sql = IF(@col_exists = 0, 'ALTER TABLE fact_whatsapp_message ADD COLUMN template_name VARCHAR(255) NULL', 'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
