From cd9c23767f58092c1b8598cb87906ffb088bbb6e Mon Sep 17 00:00:00 2001 From: PainAlternates Date: Mon, 22 Jan 2024 05:26:24 +0300 Subject: [PATCH] An actual replacement for MySQL usage of IF EXISTS --- Shoko.Server/Databases/MySQL.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Shoko.Server/Databases/MySQL.cs b/Shoko.Server/Databases/MySQL.cs index faa25401e..1edaba3bb 100644 --- a/Shoko.Server/Databases/MySQL.cs +++ b/Shoko.Server/Databases/MySQL.cs @@ -745,16 +745,16 @@ public class MySQL : BaseDatabase new DatabaseCommand(119, 3, "DELETE FROM GroupFilter WHERE FilterType = 2; DELETE FROM GroupFilter WHERE FilterType = 16;"), new DatabaseCommand(119, 4, DatabaseFixes.MigrateGroupFilterToFilterPreset), new DatabaseCommand(119, 5, DatabaseFixes.DropGroupFilter), - new DatabaseCommand(120, 1, "IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'AnimeGroup' AND column_name = 'SortName') THEN ALTER TABLE AnimeGroup DROP COLUMN SortName; END IF;"), - new DatabaseCommand(121, 1, "IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'AnimeEpisode' AND column_name = 'PlexContractVersion') THEN ALTER TABLE AnimeEpisode DROP COLUMN PlexContractVersion; END IF;"), - new DatabaseCommand(121, 2, "IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'AnimeEpisode' AND column_name = 'PlexContractBlob') THEN ALTER TABLE AnimeEpisode DROP COLUMN PlexContractBlob; END IF;"), - new DatabaseCommand(121, 3, "IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'AnimeEpisode' AND column_name = 'PlexContractSize') THEN ALTER TABLE AnimeEpisode DROP COLUMN PlexContractSize; END IF;"), - new DatabaseCommand(121, 4, "IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'AnimeGroup_User' AND column_name = 'PlexContractVersion') THEN ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractVersion; END IF;"), - new DatabaseCommand(121, 5, "IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'AnimeGroup_User' AND column_name = 'PlexContractBlob') THEN ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractBlob; END IF;"), - new DatabaseCommand(121, 6, "IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'AnimeGroup_User' AND column_name = 'PlexContractSize') THEN ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractSize; END IF;"), - new DatabaseCommand(121, 7, "IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'AnimeSeries_User' AND column_name = 'PlexContractVersion') THEN ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractVersion; END IF;"), - new DatabaseCommand(121, 8, "IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'AnimeSeries_User' AND column_name = 'PlexContractBlob') THEN ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractBlob; END IF;"), - new DatabaseCommand(121, 9, "IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'AnimeSeries_User' AND column_name = 'PlexContractSize') THEN ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractSize; END IF;"), + new DatabaseCommand(120, 1, "SET @exist_Check := (SELECT count(1) FROM information_schema.columns WHERE TABLE_NAME='AnimeGroup' AND COLUMN_NAME='SortName' AND TABLE_SCHEMA=database()) ; SET @sqlstmt := IF(@exist_Check>0,'ALTER TABLE AnimeGroup DROP COLUMN SortName', 'SELECT ''''') ; PREPARE stmt FROM @sqlstmt ; EXECUTE stmt ;"), + new DatabaseCommand(121, 1, "SET @exist_Check := (SELECT count(1) FROM information_schema.columns WHERE TABLE_NAME='AnimeEpisode' AND COLUMN_NAME='PlexContractVersion' AND TABLE_SCHEMA=database()) ; SET @sqlstmt := IF(@exist_Check>0,'ALTER TABLE AnimeEpisode DROP COLUMN PlexContractVersion', 'SELECT ''''') ; PREPARE stmt FROM @sqlstmt ; EXECUTE stmt ;"), + new DatabaseCommand(121, 2, "SET @exist_Check := (SELECT count(1) FROM information_schema.columns WHERE TABLE_NAME='AnimeEpisode' AND COLUMN_NAME='PlexContractBlob' AND TABLE_SCHEMA=database()) ; SET @sqlstmt := IF(@exist_Check>0,'ALTER TABLE AnimeEpisode DROP COLUMN PlexContractBlob', 'SELECT ''''') ; PREPARE stmt FROM @sqlstmt ; EXECUTE stmt ;"), + new DatabaseCommand(121, 3, "SET @exist_Check := (SELECT count(1) FROM information_schema.columns WHERE TABLE_NAME='AnimeEpisode' AND COLUMN_NAME='PlexContractSize' AND TABLE_SCHEMA=database()) ; SET @sqlstmt := IF(@exist_Check>0,'ALTER TABLE AnimeEpisode DROP COLUMN PlexContractSize', 'SELECT ''''') ; PREPARE stmt FROM @sqlstmt ; EXECUTE stmt ;"), + new DatabaseCommand(121, 4, "SET @exist_Check := (SELECT count(1) FROM information_schema.columns WHERE TABLE_NAME='AnimeGroup_User' AND COLUMN_NAME='PlexContractVersion' AND TABLE_SCHEMA=database()) ; SET @sqlstmt := IF(@exist_Check>0,'ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractVersion', 'SELECT ''''') ; PREPARE stmt FROM @sqlstmt ; EXECUTE stmt ;"), + new DatabaseCommand(121, 5, "SET @exist_Check := (SELECT count(1) FROM information_schema.columns WHERE TABLE_NAME='AnimeGroup_User' AND COLUMN_NAME='PlexContractBlob' AND TABLE_SCHEMA=database()) ; SET @sqlstmt := IF(@exist_Check>0,'ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractBlob', 'SELECT ''''') ; PREPARE stmt FROM @sqlstmt ; EXECUTE stmt ;"), + new DatabaseCommand(121, 6, "SET @exist_Check := (SELECT count(1) FROM information_schema.columns WHERE TABLE_NAME='AnimeGroup_User' AND COLUMN_NAME='PlexContractSize' AND TABLE_SCHEMA=database()) ; SET @sqlstmt := IF(@exist_Check>0,'ALTER TABLE AnimeGroup_User DROP COLUMN PlexContractSize', 'SELECT ''''') ; PREPARE stmt FROM @sqlstmt ; EXECUTE stmt ;"), + new DatabaseCommand(121, 7, "SET @exist_Check := (SELECT count(1) FROM information_schema.columns WHERE TABLE_NAME='AnimeSeries_User' AND COLUMN_NAME='PlexContractVersion' AND TABLE_SCHEMA=database()) ; SET @sqlstmt := IF(@exist_Check>0,'ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractVersion', 'SELECT ''''') ; PREPARE stmt FROM @sqlstmt ; EXECUTE stmt ;"), + new DatabaseCommand(121, 8, "SET @exist_Check := (SELECT count(1) FROM information_schema.columns WHERE TABLE_NAME='AnimeSeries_User' AND COLUMN_NAME='PlexContractBlob' AND TABLE_SCHEMA=database()) ; SET @sqlstmt := IF(@exist_Check>0,'ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractBlob', 'SELECT ''''') ; PREPARE stmt FROM @sqlstmt ; EXECUTE stmt ;"), + new DatabaseCommand(121, 9, "SET @exist_Check := (SELECT count(1) FROM information_schema.columns WHERE TABLE_NAME='AnimeSeries_User' AND COLUMN_NAME='PlexContractSize' AND TABLE_SCHEMA=database()) ; SET @sqlstmt := IF(@exist_Check>0,'ALTER TABLE AnimeSeries_User DROP COLUMN PlexContractSize', 'SELECT ''''') ; PREPARE stmt FROM @sqlstmt ; EXECUTE stmt ;"), new DatabaseCommand(122, 1, "ALTER TABLE CommandRequest ADD INDEX IX_CommandRequest_CommandType (CommandType); ALTER TABLE CommandRequest ADD INDEX IX_CommandRequest_Priority_Date (Priority, DateTimeUpdated);"), }; @@ -996,7 +996,7 @@ public override string GetConnectionString() { var settings = Utils.SettingsProvider.GetSettings(); return - $"Server={settings.Database.Hostname};Port={settings.Database.Port};Database={settings.Database.Schema};User ID={settings.Database.Username};Password={settings.Database.Password};Default Command Timeout=3600"; + $"Server={settings.Database.Hostname};Port={settings.Database.Port};Database={settings.Database.Schema};User ID={settings.Database.Username};Password={settings.Database.Password};Default Command Timeout=3600;Allow User Variables=true"; } public override string GetTestConnectionString()