Skip to content

Commit

Permalink
An actual replacement for MySQL usage of IF EXISTS
Browse files Browse the repository at this point in the history
  • Loading branch information
pnlt-s authored and da3dsoul committed Mar 1, 2024
1 parent 5c7be69 commit cd9c237
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Shoko.Server/Databases/MySQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,16 +745,16 @@ public class MySQL : BaseDatabase<MySqlConnection>
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);"),
};

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit cd9c237

Please sign in to comment.