From 0e133daa8beaa7dd7c9a2852e738112160e5ac96 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 23 Sep 2016 16:22:35 +0000 Subject: [PATCH] schema: fix legacy booleans stored as strings fixes #12526 --- schema/mysql-migrations/upgrade_110.sql | 104 ++++++++++++++++++++++++ schema/mysql.sql | 2 +- schema/pgsql-migrations/upgrade_110.sql | 104 ++++++++++++++++++++++++ schema/pgsql.sql | 2 +- 4 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 schema/mysql-migrations/upgrade_110.sql create mode 100644 schema/pgsql-migrations/upgrade_110.sql diff --git a/schema/mysql-migrations/upgrade_110.sql b/schema/mysql-migrations/upgrade_110.sql new file mode 100644 index 00000000..800f7ab1 --- /dev/null +++ b/schema/mysql-migrations/upgrade_110.sql @@ -0,0 +1,104 @@ +UPDATE icinga_host_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_host_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_service_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_service_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + + +UPDATE icinga_command_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_command_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_user_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_user_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_notification_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_notification_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (110, NOW()); diff --git a/schema/mysql.sql b/schema/mysql.sql index 8e519510..0829d782 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -1326,4 +1326,4 @@ CREATE TABLE sync_run ( INSERT INTO director_schema_migration SET migration_time = NOW(), - schema_version = 109; + schema_version = 110; diff --git a/schema/pgsql-migrations/upgrade_110.sql b/schema/pgsql-migrations/upgrade_110.sql new file mode 100644 index 00000000..800f7ab1 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_110.sql @@ -0,0 +1,104 @@ +UPDATE icinga_host_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_host_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_service_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_service_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + + +UPDATE icinga_command_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_command_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_user_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_user_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_notification_var + SET varvalue = 'false', + format = 'json' + WHERE varvalue = 'n' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +UPDATE icinga_notification_var + SET varvalue = 'true', + format = 'json' + WHERE varvalue = 'y' + AND varname IN ( + SELECT DISTINCT varname + FROM director_datafield + WHERE datatype LIKE '%DataTypeBoolean' + ); + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (110, NOW()); diff --git a/schema/pgsql.sql b/schema/pgsql.sql index 3b6d9ba5..98418a05 100644 --- a/schema/pgsql.sql +++ b/schema/pgsql.sql @@ -1545,4 +1545,4 @@ CREATE UNIQUE INDEX notification_inheritance ON icinga_notification_inheritance INSERT INTO director_schema_migration (schema_version, migration_time) - VALUES (109, NOW()); + VALUES (110, NOW());