-- Compatibility patch: safely add priority column to tickets if missing (avoids MySQL IF NOT EXISTS syntax issues)
SET @db := DATABASE();
SET @has_priority := (
  SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA=@db AND TABLE_NAME='tickets' AND COLUMN_NAME='priority'
);

SET @sql := IF(@has_priority=0,
  "ALTER TABLE `tickets` ADD COLUMN `priority` ENUM('low','medium','high','urgent') DEFAULT 'medium' AFTER `status`",
  'SELECT 1'
);
PREPARE s FROM @sql; EXECUTE s; DEALLOCATE PREPARE s;
