[cloud-*] Switch MySQL charset to utf8mb4

Summary:
We need this in order to be able to store 4-byte emoji and other
extended unicode characters in the database.

Test Plan: deploy to staging - need the change that sets the connection charset on staging :(

Reviewers: khamidou, juan, evan

Reviewed By: juan, evan

Differential Revision: https://phab.nylas.com/D4387
This commit is contained in:
Christine Spang 2017-04-06 15:57:14 -07:00
parent 3074ee2912
commit d09312c27f
4 changed files with 19 additions and 5 deletions

View file

@ -27,4 +27,5 @@ module.exports = {
executeJasmine: require('./spec/jasmine/execute').default,
StringUtils: require('./src/string-utils'),
TLSUtils: require('./src/tls-utils'),
DBUtils: require('./src/db-utils'),
}

View file

@ -0,0 +1,11 @@
// In order to be able to represent 4-byte characters such as some emoji, we
// must use the 'utf8mb4' character set on MySQL. Any table using this
// character set can't have indexes on fields longer than this length without
// triggering the error
//
// ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
//
// (or, without sql_mode = TRADITIONAL - getting silently truncated!)
const MAX_INDEXABLE_LENGTH = 191;
export {MAX_INDEXABLE_LENGTH};

View file

@ -2,6 +2,7 @@ const crypto = require('crypto');
const {JSONColumn, JSONArrayColumn} = require('../database-types');
const {credentialsForProvider, smtpConfigFromSettings} = require('../auth-helpers');
const {MAX_INDEXABLE_LENGTH} = require('../db-utils');
const {DB_ENCRYPTION_ALGORITHM, DB_ENCRYPTION_PASSWORD} = process.env;
@ -11,7 +12,7 @@ module.exports = (sequelize, Sequelize) => {
id: { type: Sequelize.STRING(65), primaryKey: true },
name: Sequelize.STRING,
provider: Sequelize.STRING,
emailAddress: Sequelize.STRING,
emailAddress: Sequelize.STRING(MAX_INDEXABLE_LENGTH),
connectionSettings: JSONColumn('connectionSettings'),
connectionCredentials: Sequelize.TEXT,
syncPolicy: JSONColumn('syncPolicy'),

View file

@ -1,11 +1,12 @@
const {JSONArrayColumn} = require('../database-types');
const {MAX_INDEXABLE_LENGTH} = require('../db-utils');
module.exports = (sequelize, Sequelize) => {
return sequelize.define('transaction', {
event: Sequelize.STRING,
object: Sequelize.STRING,
objectId: Sequelize.STRING,
accountId: Sequelize.STRING,
event: Sequelize.STRING(MAX_INDEXABLE_LENGTH),
object: Sequelize.STRING(MAX_INDEXABLE_LENGTH),
objectId: Sequelize.STRING(MAX_INDEXABLE_LENGTH),
accountId: Sequelize.STRING(MAX_INDEXABLE_LENGTH),
changedFields: JSONArrayColumn('changedFields'),
}, {
indexes: [