From e8dddac1423173bb95c784b52f627a69f1ed016c Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 17 Jan 2018 10:01:16 -0500 Subject: [PATCH] only rename the columns if they exist. Makes this update re-runnable --- db/zm_update-1.31.23.sql | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/db/zm_update-1.31.23.sql b/db/zm_update-1.31.23.sql index 46f72e57c..1e4b6795c 100644 --- a/db/zm_update-1.31.23.sql +++ b/db/zm_update-1.31.23.sql @@ -1,3 +1,35 @@ -ALTER TABLE Servers CHANGE COLUMN `zmstats.pl` `zmstats` BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE Servers CHANGE COLUMN `zmaudit.pl` `zmaudit` BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE Servers CHANGE COLUMN `zmtrigger.pl` `zmtrigger` BOOLEAN NOT NULL DEFAULT FALSE; +SET @s = (SELECT IF( + (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE() + AND table_name = 'Servers' + AND column_name = 'zmstats.pl' + ) > 0, + "ALTER TABLE Servers CHANGE COLUMN `zmstats.pl` `zmstats` BOOLEAN NOT NULL DEFAULT FALSE", + "SELECT 'zmstats.pl has already been changed to zmstats'" + )); + +PREPARE stmt FROM @s; +EXECUTE stmt; + +SET @s = (SELECT IF( + (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE() + AND table_name = 'Servers' + AND column_name = 'zmaudit.pl' + ) > 0, + "ALTER TABLE Servers CHANGE COLUMN `zmaudit.pl` `zmaudit` BOOLEAN NOT NULL DEFAULT FALSE", + "SELECT 'zmaudit.pl has already been changed to zmaudit'" + )); + +PREPARE stmt FROM @s; +EXECUTE stmt; + +SET @s = (SELECT IF( + (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE() + AND table_name = 'Servers' + AND column_name = 'zmtrigger.pl' + ) > 0, + "ALTER TABLE Servers CHANGE COLUMN `zmtrigger.pl` `zmtrigger` BOOLEAN NOT NULL DEFAULT FALSE", + "SELECT 'zmtrigger.pl has already been changed to zmtrigger'" + )); + +PREPARE stmt FROM @s; +EXECUTE stmt;