From 4924ebb2118d760f202c096b45b8a126adee5716 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 1 Nov 2023 11:43:00 -0400 Subject: [PATCH] Redo the update for User_Preferences. Sourcing User_Preferences.sql drops the table, losing contents. --- db/zm_update-1.37.38.sql | 39 +++++++++++++++++++++++++++++++++++++ db/zm_update-1.37.38.sql.in | 1 - db/zm_update-1.37.47.sql | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 db/zm_update-1.37.38.sql delete mode 100644 db/zm_update-1.37.38.sql.in create mode 100644 db/zm_update-1.37.47.sql diff --git a/db/zm_update-1.37.38.sql b/db/zm_update-1.37.38.sql new file mode 100644 index 000000000..0007cf7c8 --- /dev/null +++ b/db/zm_update-1.37.38.sql @@ -0,0 +1,39 @@ +-- +-- This adds Manufacturers and Models +-- + +SET @s = (SELECT IF( + (SELECT COUNT(*) + FROM INFORMATION_SCHEMA.TABLES + WHERE table_name = 'User_Preferences' + AND table_schema = DATABASE() + ) > 0, + "SELECT 'User_Preferences table exists'", + " +CREATE TABLE `User_Preferences` ( + `Id` int(10) unsigned NOT NULL auto_increment, + `UserId` int(10) unsigned NOT NULL, + FOREIGN KEY (UserId) REFERENCES Users(Id), + `Name` varchar(64), + `Value` TEXT, + PRIMARY KEY (Id) +) + " + )); + +PREPARE stmt FROM @s; +EXECUTE stmt; + +SET @s = (SELECT IF( + (SELECT COUNT(*) + FROM INFORMATION_SCHEMA.STATISTICS + WHERE table_name = 'User_Preferences' + AND table_schema = DATABASE() + AND index_name = 'User_Preferences_UserID_idx' + ) > 0, +"SELECT 'UserId Index already exists on User_Preferences table'", +"CREATE INDEX User_Preferences_UserID_idx on User_Preferences (`UserId`)" +)); + +PREPARE stmt FROM @s; +EXECUTE stmt; diff --git a/db/zm_update-1.37.38.sql.in b/db/zm_update-1.37.38.sql.in deleted file mode 100644 index 33971270e..000000000 --- a/db/zm_update-1.37.38.sql.in +++ /dev/null @@ -1 +0,0 @@ -source @PKGDATADIR@/db/User_Preferences.sql diff --git a/db/zm_update-1.37.47.sql b/db/zm_update-1.37.47.sql new file mode 100644 index 000000000..0007cf7c8 --- /dev/null +++ b/db/zm_update-1.37.47.sql @@ -0,0 +1,39 @@ +-- +-- This adds Manufacturers and Models +-- + +SET @s = (SELECT IF( + (SELECT COUNT(*) + FROM INFORMATION_SCHEMA.TABLES + WHERE table_name = 'User_Preferences' + AND table_schema = DATABASE() + ) > 0, + "SELECT 'User_Preferences table exists'", + " +CREATE TABLE `User_Preferences` ( + `Id` int(10) unsigned NOT NULL auto_increment, + `UserId` int(10) unsigned NOT NULL, + FOREIGN KEY (UserId) REFERENCES Users(Id), + `Name` varchar(64), + `Value` TEXT, + PRIMARY KEY (Id) +) + " + )); + +PREPARE stmt FROM @s; +EXECUTE stmt; + +SET @s = (SELECT IF( + (SELECT COUNT(*) + FROM INFORMATION_SCHEMA.STATISTICS + WHERE table_name = 'User_Preferences' + AND table_schema = DATABASE() + AND index_name = 'User_Preferences_UserID_idx' + ) > 0, +"SELECT 'UserId Index already exists on User_Preferences table'", +"CREATE INDEX User_Preferences_UserID_idx on User_Preferences (`UserId`)" +)); + +PREPARE stmt FROM @s; +EXECUTE stmt;