52 lines
1.4 KiB
SQL
52 lines
1.4 KiB
SQL
-- +goose Up
|
|
SET @bases_exists := (
|
|
SELECT COUNT(*)
|
|
FROM information_schema.tables
|
|
WHERE table_schema = DATABASE()
|
|
AND table_name = 'bases'
|
|
);
|
|
|
|
SET @col_default_shift_time_exists := (
|
|
SELECT COUNT(*)
|
|
FROM information_schema.columns
|
|
WHERE table_schema = DATABASE()
|
|
AND table_name = 'bases'
|
|
AND column_name = 'default_shift_time'
|
|
);
|
|
|
|
SET @drop_default_shift_time_sql := IF(
|
|
@bases_exists > 0 AND @col_default_shift_time_exists > 0,
|
|
'ALTER TABLE bases DROP COLUMN default_shift_time',
|
|
'SELECT 1'
|
|
);
|
|
|
|
PREPARE stmt_drop_default_shift_time FROM @drop_default_shift_time_sql;
|
|
EXECUTE stmt_drop_default_shift_time;
|
|
DEALLOCATE PREPARE stmt_drop_default_shift_time;
|
|
|
|
-- +goose Down
|
|
SET @bases_exists := (
|
|
SELECT COUNT(*)
|
|
FROM information_schema.tables
|
|
WHERE table_schema = DATABASE()
|
|
AND table_name = 'bases'
|
|
);
|
|
|
|
SET @col_default_shift_time_exists := (
|
|
SELECT COUNT(*)
|
|
FROM information_schema.columns
|
|
WHERE table_schema = DATABASE()
|
|
AND table_name = 'bases'
|
|
AND column_name = 'default_shift_time'
|
|
);
|
|
|
|
SET @add_default_shift_time_sql := IF(
|
|
@bases_exists > 0 AND @col_default_shift_time_exists = 0,
|
|
'ALTER TABLE bases ADD COLUMN default_shift_time VARCHAR(64) NULL AFTER default_shift_end',
|
|
'SELECT 1'
|
|
);
|
|
|
|
PREPARE stmt_add_default_shift_time FROM @add_default_shift_time_sql;
|
|
EXECUTE stmt_add_default_shift_time;
|
|
DEALLOCATE PREPARE stmt_add_default_shift_time;
|