-- Phase M21 — add per-DZ runway / jump-run heading for the
-- Automated Meteorological Manifest Framework.
--
-- `runway_heading_deg` is the primary runway axis in degrees
-- (0–359, 0 = N). Feeds into the deterministic eligibility
-- subsystem to decompose wind into headwind / crosswind
-- components. Nullable so unregistered DZs stay valid.
--
-- Idempotent: uses a stored procedure + `INFORMATION_SCHEMA`
-- lookup so re-running the migration is safe (matches the
-- pattern used by earlier SkyLara migrations).

DELIMITER $$

DROP PROCEDURE IF EXISTS add_runway_heading_deg $$
CREATE PROCEDURE add_runway_heading_deg()
BEGIN
  IF NOT EXISTS (
    SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'Dropzone'
      AND COLUMN_NAME = 'runwayHeadingDeg'
  ) THEN
    ALTER TABLE `Dropzone`
      ADD COLUMN `runwayHeadingDeg` INT NULL
        COMMENT 'Primary runway / jump-run heading in degrees (0-359, 0 = N). Feeds meteo eligibility.';
  END IF;
END $$

CALL add_runway_heading_deg() $$
DROP PROCEDURE add_runway_heading_deg $$

DELIMITER ;
