Files
fm_be/migrations/20260626_flight_data_pilot_id_nullable.sql
2026-07-16 22:16:45 +07:00

34 lines
741 B
SQL

-- +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;