-- Migration 71: Add reminder_at to customer_notes table

SET @column_exists = (
    SELECT COUNT(*)
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'customer_notes'
      AND COLUMN_NAME = 'reminder_at'
);

SET @stmt = IF(@column_exists = 0,
    'ALTER TABLE `customer_notes` 
        ADD COLUMN `reminder_at` DATETIME NULL AFTER `note`,
        ADD KEY `idx_customer_notes_reminder_at` (`reminder_at`)',
    'SELECT 1'
);

PREPARE alter_stmt FROM @stmt;
EXECUTE alter_stmt;
DEALLOCATE PREPARE alter_stmt;
