Skip to content

Commit

Permalink
schema: Change character set to utf8mb4 (support for Emojis in Menus/…
Browse files Browse the repository at this point in the history
…Pages/News/Forum etc.)
  • Loading branch information
slawkens committed Nov 22, 2024
1 parent 3f6ff3a commit 27c44f1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
2 changes: 1 addition & 1 deletion common.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

const MYAAC = true;
const MYAAC_VERSION = '1.0-RC.2';
const DATABASE_VERSION = 40;
const DATABASE_VERSION = 41;
const TABLE_PREFIX = 'myaac_';
define('START_TIME', microtime(true));
define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX'));
Expand Down
40 changes: 20 additions & 20 deletions install/includes/schema.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SET @myaac_database_version = 40;
SET @myaac_database_version = 41;

CREATE TABLE `myaac_account_actions`
(
Expand All @@ -8,7 +8,7 @@ CREATE TABLE `myaac_account_actions`
`date` INT(11) NOT NULL DEFAULT 0,
`action` VARCHAR(255) NOT NULL DEFAULT '',
KEY (`account_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_admin_menu`
(
Expand All @@ -19,7 +19,7 @@ CREATE TABLE `myaac_admin_menu`
`flags` INT(11) NOT NULL DEFAULT 0,
`enabled` INT(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_bugtracker`
(
Expand All @@ -34,7 +34,7 @@ CREATE TABLE `myaac_bugtracker`
`uid` INT(11) NOT NULL AUTO_INCREMENT,
`tag` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_changelog`
(
Expand All @@ -46,7 +46,7 @@ CREATE TABLE `myaac_changelog`
`player_id` INT(11) NOT NULL DEFAULT 0,
`hide` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

INSERT INTO `myaac_changelog` (`id`, `type`, `where`, `date`, `body`, `hide`) VALUES (1, 3, 2, UNIX_TIMESTAMP(), 'MyAAC installed. (:', 0);

Expand All @@ -57,7 +57,7 @@ CREATE TABLE `myaac_config`
`value` VARCHAR(1000) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE (`name`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

INSERT INTO `myaac_config` (`name`, `value`) VALUES ('database_version', @myaac_database_version);

Expand All @@ -69,7 +69,7 @@ CREATE TABLE `myaac_faq`
`ordering` INT(11) NOT NULL DEFAULT 0,
`hide` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_forum_boards`
(
Expand All @@ -82,7 +82,7 @@ CREATE TABLE `myaac_forum_boards`
`closed` TINYINT(1) NOT NULL DEFAULT 0,
`hide` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;
INSERT INTO `myaac_forum_boards` (`id`, `name`, `description`, `ordering`, `closed`) VALUES (NULL, 'News', 'News commenting', 0, 1);
INSERT INTO `myaac_forum_boards` (`id`, `name`, `description`, `ordering`) VALUES (NULL, 'Trade', 'Trade offers.', 1);
INSERT INTO `myaac_forum_boards` (`id`, `name`, `description`, `ordering`) VALUES (NULL, 'Quests', 'Quest making.', 2);
Expand Down Expand Up @@ -111,7 +111,7 @@ CREATE TABLE `myaac_forum`
`closed` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `section` (`section`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_menu`
(
Expand All @@ -125,7 +125,7 @@ CREATE TABLE `myaac_menu`
`ordering` INT(11) NOT NULL DEFAULT 0,
`enabled` INT(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_monsters` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand Down Expand Up @@ -158,7 +158,7 @@ CREATE TABLE `myaac_monsters` (
`loot` text NOT NULL,
`summons` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_news`
(
Expand All @@ -176,7 +176,7 @@ CREATE TABLE `myaac_news`
`article_image` VARCHAR(100) NOT NULL DEFAULT '',
`hide` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_news_categories`
(
Expand All @@ -186,7 +186,7 @@ CREATE TABLE `myaac_news_categories`
`icon_id` INT(2) NOT NULL DEFAULT 0,
`hide` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

INSERT INTO `myaac_news_categories` (`id`, `icon_id`) VALUES (NULL, 0);
INSERT INTO `myaac_news_categories` (`id`, `icon_id`) VALUES (NULL, 1);
Expand All @@ -202,7 +202,7 @@ CREATE TABLE `myaac_notepad`
`content` TEXT NOT NULL,
/*`public` TINYINT(1) NOT NULL DEFAULT 0*/
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_pages`
(
Expand All @@ -218,7 +218,7 @@ CREATE TABLE `myaac_pages`
`hide` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE (`name`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_gallery`
(
Expand All @@ -230,7 +230,7 @@ CREATE TABLE `myaac_gallery`
`ordering` INT(11) NOT NULL DEFAULT 0,
`hide` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

INSERT INTO `myaac_gallery` (`id`, `ordering`, `comment`, `image`, `thumb`, `author`) VALUES (NULL, 1, 'Demon', 'images/gallery/demon.jpg', 'images/gallery/demon_thumb.gif', 'MyAAC');

Expand All @@ -242,7 +242,7 @@ CREATE TABLE `myaac_settings`
`value` TEXT NOT NULL,
PRIMARY KEY (`id`),
KEY `key` (`key`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_spells`
(
Expand All @@ -265,7 +265,7 @@ CREATE TABLE `myaac_spells`
`hide` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE (`name`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_visitors`
(
Expand All @@ -274,7 +274,7 @@ CREATE TABLE `myaac_visitors`
`page` VARCHAR(2048) NOT NULL,
`user_agent` VARCHAR(255) NOT NULL DEFAULT '',
UNIQUE (`ip`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

CREATE TABLE `myaac_weapons`
(
Expand All @@ -283,4 +283,4 @@ CREATE TABLE `myaac_weapons`
`maglevel` INT(11) NOT NULL DEFAULT 0,
`vocations` VARCHAR(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;
35 changes: 35 additions & 0 deletions system/migrations/41.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Change database tables character set to utf8mb4
* Previously it was utf8 (utf8mb3)
* utf8 will become utf8mb4 in future releases of mysql
*/
$tables = [
'account_actions', 'admin_menu',
'changelog', 'config',
'faq', 'forum_boards', 'forum',
'gallery',
'menu', 'monsters',
'news', 'news_categories', 'notepad',
'pages',
'settings', 'spells',
'visitors', 'weapons',
];

$up = function () use ($db, $tables)
{
foreach ($tables as $table) {
if ($db->hasTable(TABLE_PREFIX . $table)) {
$db->exec('ALTER TABLE ' . TABLE_PREFIX . $table . ' CONVERT TO CHARACTER SET utf8mb4');
}
}
};

$down = function () use ($db, $tables)
{
foreach ($tables as $table) {
if ($db->hasTable(TABLE_PREFIX . $table)) {
$db->exec('ALTER TABLE ' . TABLE_PREFIX . $table . ' CONVERT TO CHARACTER SET utf8');
}
}
};

0 comments on commit 27c44f1

Please sign in to comment.