-- 0018 — Load.exitAltitudeFt
--
-- Phase R5.1 (2026-04-15). Adds the operator-set exit altitude that
-- the detail page was displaying "— ft" for since Phase 1. Nullable;
-- falls back to the dropzone default in the UI when unset.
--
-- Additive, idempotent.

DROP PROCEDURE IF EXISTS sky_add_col_if_missing_0018;
DELIMITER $$
CREATE PROCEDURE sky_add_col_if_missing_0018(
  IN t_name VARCHAR(64),
  IN c_name VARCHAR(64),
  IN c_def  VARCHAR(200)
)
BEGIN
  IF NOT EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_schema = DATABASE()
      AND table_name   = t_name
      AND column_name  = c_name
  ) THEN
    SET @sql := CONCAT('ALTER TABLE `', t_name, '` ADD COLUMN `', c_name, '` ', c_def);
    PREPARE stmt FROM @sql;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
  END IF;
END$$
DELIMITER ;

CALL sky_add_col_if_missing_0018('loads', 'exitAltitudeFt', 'INT NULL');

DROP PROCEDURE IF EXISTS sky_add_col_if_missing_0018;
