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

SET @sql := IF(
  @has_status = 0,
  'ALTER TABLE flight_data ADD COLUMN status VARCHAR(20) NOT NULL DEFAULT ''on_going'' AFTER id',
  'SELECT 1'
);

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

UPDATE flight_data
SET status = 'on_going'
WHERE status IS NULL OR status = '';

-- +goose Down
SET @has_status := (
  SELECT COUNT(*)
  FROM information_schema.columns
  WHERE table_schema = DATABASE()
    AND table_name = 'flight_data'
    AND column_name = 'status'
);

SET @sql := IF(
  @has_status = 1,
  'ALTER TABLE flight_data DROP COLUMN status',
  'SELECT 1'
);

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