-- +goose Up SET @has_col := ( SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'flight_data' AND column_name = 'pilot_id' ); SET @sql := IF( @has_col = 1, 'ALTER TABLE flight_data MODIFY COLUMN pilot_id BINARY(16) NULL', '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 = 'pilot_id' ); SET @sql := IF( @has_col = 1, 'ALTER TABLE flight_data MODIFY COLUMN pilot_id BINARY(16) NOT NULL', 'SELECT 1' ); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;