-- Fix for missing template_description column
-- Run this if you get error: #1054 - Unknown column 'template_description' in 'field list'

-- Check if column exists and add it if it doesn't
SET @sql = (SELECT IF(
    (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS 
     WHERE TABLE_SCHEMA = DATABASE() 
     AND TABLE_NAME = 'question_pattern_templates' 
     AND COLUMN_NAME = 'template_description') = 0,
    'ALTER TABLE question_pattern_templates ADD COLUMN template_description TEXT AFTER template_name',
    'SELECT "Column template_description already exists" as message'
));

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- Verify the column exists
SELECT 'template_description column check completed' as status;
