-- +goose Up
SET @has_col := (
  SELECT COUNT(*)
  FROM information_schema.columns
  WHERE table_schema = DATABASE()
    AND table_name = 'flight_data'
    AND column_name = 'flight_position'
);
SET @sql := IF(
  @has_col = 0,
  'ALTER TABLE flight_data ADD COLUMN flight_position TINYINT(1) NOT NULL DEFAULT 0 AFTER fuel_planning',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- +goose Down
SET @has_col := (
  SELECT COUNT(*)
  FROM information_schema.columns
  WHERE table_schema = DATABASE()
    AND table_name = 'flight_data'
    AND column_name = 'flight_position'
);
SET @sql := IF(
  @has_col = 1,
  'ALTER TABLE flight_data DROP COLUMN flight_position',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
