USE trainer_attendance;

SET @col := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'courses' AND COLUMN_NAME = 'location_type'
);
SET @sql := IF(@col = 0,
  "ALTER TABLE courses ADD COLUMN location_type ENUM('inside_iraq','outside_iraq') NOT NULL DEFAULT 'inside_iraq' AFTER end_date",
  'SELECT 1');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
