Skip to content

Commit

Permalink
Convert database structure to InnoDB with utf8mb4
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMinekus committed Nov 15, 2020
1 parent a338bf4 commit a07df02
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion game_upload/addons/sourcemod/scripting/sourcebans.sp
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ public GotDatabase(Handle:owner, Handle:hndl, const String:error[], any:data)
DB = hndl;

decl String:query[1024];
FormatEx(query, sizeof(query), "SET NAMES \"UTF8\"");
FormatEx(query, sizeof(query), "SET NAMES \"utf8mb4\"");
SQL_TQuery(DB, ErrorCheckCallback, query);

InsertServerInfo();
Expand Down
2 changes: 1 addition & 1 deletion web_upload/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function sbError($errno, $errstr, $errfile, $errline)
define('ALL_SERVER', SM_RESERVED_SLOT.SM_GENERIC.SM_KICK.SM_BAN.SM_UNBAN.SM_SLAY.SM_MAP.SM_CVAR.SM_CONFIG.SM_VOTE.SM_PASSWORD.SM_RCON.
SM_CHEATS.SM_CUSTOM1.SM_CUSTOM2.SM_CUSTOM3. SM_CUSTOM4.SM_CUSTOM5.SM_CUSTOM6.SM_ROOT);

$GLOBALS['db']->Execute("SET NAMES utf8;");
$GLOBALS['db']->Execute("SET NAMES utf8mb4;");

$res = $GLOBALS['db']->Execute("SELECT * FROM ".DB_PREFIX."_settings GROUP BY `setting`, `value`");
$GLOBALS['config'] = array();
Expand Down
2 changes: 1 addition & 1 deletion web_upload/install/includes/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ INSERT INTO `{prefix}_settings` (`setting`, `value`) VALUES
('config.enablefriendsbanning', '0'),
('config.enableadminrehashing', '1'),
('protest.emailonlyinvolved', '0'),
('config.version', '356');
('config.version', '400');


INSERT INTO `{prefix}_admins` (
Expand Down
34 changes: 17 additions & 17 deletions web_upload/install/includes/struc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ CREATE TABLE IF NOT EXISTS `{prefix}_admins` (
`lastvisit` int(11) NULL,
PRIMARY KEY (`aid`),
UNIQUE KEY `user` (`user`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_admins_servers_groups` (
`admin_id` int(10) NOT NULL,
`group_id` int(10) NOT NULL,
`srv_group_id` int(10) NOT NULL,
`server_id` int(10) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_banlog` (
Expand All @@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_banlog` (
`name` varchar(128) NOT NULL,
`bid` int(6) NOT NULL,
PRIMARY KEY (`sid`,`time`,`bid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_bans` (
Expand All @@ -58,7 +58,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_bans` (
KEY `sid` (`sid`),
FULLTEXT KEY `reason` (`reason`),
FULLTEXT KEY `authid_2` (`authid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_comments` (
Expand All @@ -72,7 +72,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_comments` (
`edittime` int(11) default NULL,
FULLTEXT `commenttxt` (`commenttxt`),
KEY `cid` (`cid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_demos` (
Expand All @@ -81,7 +81,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_demos` (
`filename` varchar(128) character set utf8 NOT NULL,
`origname` varchar(128) NOT NULL,
PRIMARY KEY (`demid`,`demtype`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_groups` (
Expand All @@ -90,7 +90,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_groups` (
`name` varchar(128) character set utf8 NOT NULL default 'unnamed',
`flags` int(10) NOT NULL,
PRIMARY KEY (`gid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_log` (
Expand All @@ -104,7 +104,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_log` (
`host` text NOT NULL,
`created` int(11) NOT NULL,
PRIMARY KEY (`lid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_mods` (
Expand All @@ -118,7 +118,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_mods` (
UNIQUE (`modfolder`),
UNIQUE (`name`),
INDEX (`steam_universe`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_overrides` (
Expand All @@ -128,7 +128,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_overrides` (
`flags` varchar(30) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `type` (`type`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_protests` (
Expand All @@ -142,7 +142,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_protests` (
`pip` varchar(64) NOT NULL,
PRIMARY KEY (`pid`),
KEY `bid` (`bid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_servers` (
Expand All @@ -154,21 +154,21 @@ CREATE TABLE IF NOT EXISTS `{prefix}_servers` (
`enabled` TINYINT NOT NULL DEFAULT '1',
PRIMARY KEY (`sid`),
UNIQUE KEY `ip` (`ip`,`port`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_servers_groups` (
`server_id` int(10) NOT NULL,
`group_id` int(10) NOT NULL,
PRIMARY KEY (`server_id`,`group_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_settings` (
`setting` varchar(128) NOT NULL,
`value` text NOT NULL,
UNIQUE KEY `setting` (`setting`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_srvgroups` (
Expand All @@ -178,7 +178,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_srvgroups` (
`name` varchar(120) NOT NULL,
`groups_immune` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_srvgroups_overrides` (
Expand All @@ -189,7 +189,7 @@ CREATE TABLE IF NOT EXISTS `{prefix}_srvgroups_overrides` (
`access` enum('allow','deny') NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `group_id` (`group_id`,`type`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `{prefix}_submissions` (
Expand All @@ -207,4 +207,4 @@ CREATE TABLE IF NOT EXISTS `{prefix}_submissions` (
`archivedby` INT(11) NULL,
`server` tinyint(3) default NULL,
PRIMARY KEY (`subid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2 changes: 1 addition & 1 deletion web_upload/updater/data/112.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
`editaid` int(6) default NULL,
`edittime` datetime default NULL,
KEY `cid` (`cid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
if(!$ret6)
return false;

Expand Down
4 changes: 2 additions & 2 deletions web_upload/updater/data/356.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
`flags` varchar(30) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `type` (`type`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
if(!$create)
return false;

Expand All @@ -18,7 +18,7 @@
`access` enum('allow','deny') NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `group_id` (`group_id`,`type`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
if(!$create)
return false;
return true;
Expand Down
29 changes: 29 additions & 0 deletions web_upload/updater/data/400.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

$ret = $GLOBALS['db']->Execute("ALTER DATABASE `".DB_NAME."` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci");
if (!$ret)
return false;

$tables = $GLOBALS['db']->GetAll('SHOW TABLES');

foreach ($tables as $table) {
$name = $table['Tables_in_'.DB_NAME];

$ret = $GLOBALS['db']->Execute("ALTER TABLE `$name` ENGINE=InnoDB");
if (!$ret)
return false;

$ret = $GLOBALS['db']->Execute("ALTER TABLE `$name` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
if (!$ret)
return false;

$ret = $GLOBALS['db']->Execute("REPAIR TABLE `$name`");
if (!$ret)
return false;

$ret = $GLOBALS['db']->Execute("OPTIMIZE TABLE `$name`");
if (!$ret)
return false;
}

return true;
3 changes: 2 additions & 1 deletion web_upload/updater/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
353 => "353.php",
354 => "354.php",
355 => "355.php",
356 => "356.php"
356 => "356.php",
400 => "400.php",
);
?>

0 comments on commit a07df02

Please sign in to comment.