-- Keep fleet status service log schema aligned with service timestamp usage.

SET @has_status_col := (
  SELECT COUNT(*)
  FROM information_schema.columns
  WHERE table_schema = DATABASE()
    AND table_name = 'fleet_status_service_logs'
    AND column_name = 'serviced_at'
);

SET @sql := IF(
  @has_status_col = 0,
  'ALTER TABLE fleet_status_service_logs ADD COLUMN serviced_at DATETIME(3) NOT NULL AFTER ext',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
