-- +goose Up
SET @has_manual := (
  SELECT COUNT(*)
  FROM information_schema.columns
  WHERE table_schema = DATABASE()
    AND table_name = 'helicopter_usage'
    AND column_name = 'manual_airframe_hours'
);

SET @sql := IF(
  @has_manual = 0,
  'ALTER TABLE helicopter_usage
     ADD COLUMN manual_airframe_hours DECIMAL(12,2) NOT NULL DEFAULT 0,
     ADD COLUMN manual_airframe_cycles INT NOT NULL DEFAULT 0,
     ADD COLUMN manual_engine_1_hours DECIMAL(12,2) NOT NULL DEFAULT 0,
     ADD COLUMN manual_engine_1_gpc_ng_n1 DECIMAL(12,2) NOT NULL DEFAULT 0,
     ADD COLUMN manual_engine_1_ptc_nf_n2 DECIMAL(12,2) NOT NULL DEFAULT 0,
     ADD COLUMN manual_engine_2_hours DECIMAL(12,2) NOT NULL DEFAULT 0,
     ADD COLUMN manual_engine_2_gpc_ng_n1 DECIMAL(12,2) NOT NULL DEFAULT 0,
     ADD COLUMN manual_engine_2_ptc_nf_n2 DECIMAL(12,2) NOT NULL DEFAULT 0,
     ADD COLUMN manual_landing INT NOT NULL DEFAULT 0,
     ADD COLUMN manual_flight_report INT NOT NULL DEFAULT 0,
     ADD COLUMN manual_hook_release INT NOT NULL DEFAULT 0,
     ADD COLUMN manual_rotor_brake_cycle INT NOT NULL DEFAULT 0',
  'SELECT 1'
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- +goose Down
ALTER TABLE helicopter_usage
  DROP COLUMN manual_airframe_hours,
  DROP COLUMN manual_airframe_cycles,
  DROP COLUMN manual_engine_1_hours,
  DROP COLUMN manual_engine_1_gpc_ng_n1,
  DROP COLUMN manual_engine_1_ptc_nf_n2,
  DROP COLUMN manual_engine_2_hours,
  DROP COLUMN manual_engine_2_gpc_ng_n1,
  DROP COLUMN manual_engine_2_ptc_nf_n2,
  DROP COLUMN manual_landing,
  DROP COLUMN manual_flight_report,
  DROP COLUMN manual_hook_release,
  DROP COLUMN manual_rotor_brake_cycle;
