init push
This commit is contained in:
41
migrations/20260615_add_status_to_flight_data.sql
Normal file
41
migrations/20260615_add_status_to_flight_data.sql
Normal file
@@ -0,0 +1,41 @@
|
||||
-- +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;
|
||||
Reference in New Issue
Block a user