Files
fm_be/migrations/20260526_reserve_acs_add_notes.sql
2026-07-16 22:16:45 +07:00

36 lines
865 B
SQL

-- +goose Up
SET @schema_name := DATABASE();
SELECT COUNT(*) INTO @has_notes
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @schema_name
AND TABLE_NAME = 'reserve_acs'
AND COLUMN_NAME = 'notes';
SET @add_notes_sql := IF(
@has_notes = 0,
'ALTER TABLE reserve_acs ADD COLUMN notes TEXT NULL AFTER base_id',
'SELECT 1'
);
PREPARE stmt_add_notes FROM @add_notes_sql;
EXECUTE stmt_add_notes;
DEALLOCATE PREPARE stmt_add_notes;
-- +goose Down
SET @schema_name := DATABASE();
SELECT COUNT(*) INTO @has_notes
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @schema_name
AND TABLE_NAME = 'reserve_acs'
AND COLUMN_NAME = 'notes';
SET @drop_notes_sql := IF(
@has_notes = 1,
'ALTER TABLE reserve_acs DROP COLUMN notes',
'SELECT 1'
);
PREPARE stmt_drop_notes FROM @drop_notes_sql;
EXECUTE stmt_drop_notes;
DEALLOCATE PREPARE stmt_drop_notes;