Change charset for certain fields to utf8mb4

The underlying cause of #419 is the default utf8 collation in MySQL/MariaDB, which only supports the base plane of Unicode (\u0000-\uffff).  By changing the collation to utf8mb4_general_ci, stuff like ban reasons and profile text may have emoji and other non-base-plane Unicode.

The charset for playlist titles is NOT changed, and non-base-plane characters are replaced by question marks.  This is because switching to utf8mb4 would make the primary key too long.
This commit is contained in:
Calvin Montgomery 2014-12-14 21:33:48 -05:00
parent 4b8681c2a4
commit 9deff9bdb1
3 changed files with 8 additions and 5 deletions

View File

@ -1243,6 +1243,8 @@ PlaylistModule.prototype.handleClonePlaylist = function (user, data) {
});
}
data.name = data.name.replace(/[^\u0000-\uffff]/g, "?");
var pl = this.items.toArray();
var self = this;
db.saveUserPlaylist(pl, user.getName(), data.name, function (err) {

View File

@ -17,7 +17,8 @@ module.exports.init = function () {
user: Config.get("mysql.user"),
password: Config.get("mysql.password"),
database: Config.get("mysql.database"),
multipleStatements: true
multipleStatements: true,
charset: "UTF8MB4_GENERAL_CI" // Needed for emoji and other non-BMP unicode
});
// Test the connection

View File

@ -5,7 +5,7 @@ const TBL_USERS = "" +
"`password` VARCHAR(64) NOT NULL," +
"`global_rank` INT NOT NULL," +
"`email` VARCHAR(255) NOT NULL," +
"`profile` TEXT NOT NULL," +
"`profile` TEXT CHARACTER SET utf8mb4 NOT NULL," +
"`ip` VARCHAR(39) NOT NULL," + "`time` BIGINT NOT NULL," +
"PRIMARY KEY(`id`)," +
"UNIQUE(`name`)) " +
@ -23,7 +23,7 @@ const TBL_CHANNELS = "" +
const TBL_GLOBAL_BANS = "" +
"CREATE TABLE IF NOT EXISTS `global_bans` (" +
"`ip` VARCHAR(39) NOT NULL," +
"`reason` VARCHAR(255) NOT NULL," +
"`reason` VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL," +
"PRIMARY KEY (`ip`)) " +
"CHARACTER SET utf8";
@ -75,7 +75,7 @@ const TBL_META = "" +
const TBL_LIBRARIES = "" +
"CREATE TABLE IF NOT EXISTS `channel_libraries` (" +
"`id` VARCHAR(255) NOT NULL," +
"`title` VARCHAR(255) NOT NULL," +
"`title` VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL," +
"`seconds` INT NOT NULL," +
"`type` VARCHAR(2) NOT NULL," +
"`meta` TEXT NOT NULL," +
@ -97,7 +97,7 @@ const TBL_BANS = "" +
"`ip` VARCHAR(39) NOT NULL," +
"`name` VARCHAR(20) NOT NULL," +
"`bannedby` VARCHAR(20) NOT NULL," +
"`reason` VARCHAR(255) NOT NULL," +
"`reason` VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL," +
"`channel` VARCHAR(30) NOT NULL," +
"PRIMARY KEY (`id`, `channel`), UNIQUE (`name`, `ip`, `channel`), " +
"INDEX (`ip`, `channel`), INDEX (`name`, `channel`)" +