-- +goose Up
SET @needs_rename := (
  SELECT COUNT(*)
  FROM information_schema.columns
  WHERE table_schema = DATABASE()
    AND table_name = 'flight_data'
    AND column_name = 'pilot_id'
);
SET @sql := IF(
  @needs_rename = 1,
  'ALTER TABLE flight_data CHANGE COLUMN pilot_id co_pilot_id BINARY(16) NULL',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- +goose Down
SET @needs_rename := (
  SELECT COUNT(*)
  FROM information_schema.columns
  WHERE table_schema = DATABASE()
    AND table_name = 'flight_data'
    AND column_name = 'co_pilot_id'
);
SET @sql := IF(
  @needs_rename = 1,
  'ALTER TABLE flight_data CHANGE COLUMN co_pilot_id pilot_id BINARY(16) NULL',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
