@@ -15,6 +15,11 @@ const dbUtil = require('./util')
1515const REQUIRED_CHARSET = 'UTF8MB4_BIN'
1616const DATABASE_NAME = require ( '../constants' ) . DATABASE_NAME
1717
18+ const REQUIRED_SQL_MODES = [
19+ 'STRICT_ALL_TABLES' ,
20+ 'NO_ENGINE_SUBSTITUTION' ,
21+ ]
22+
1823// http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1924const ER_TOO_MANY_CONNECTIONS = 1040
2025const ER_DUP_ENTRY = 1062
@@ -67,6 +72,18 @@ module.exports = function (log, error) {
6772 options . master . charset = options . charset
6873 options . slave . charset = options . charset
6974
75+ var mode = REQUIRED_SQL_MODES . join ( ',' )
76+ if ( options . sql_mode && options . sql_mode !== mode ) {
77+ log . error ( 'createPoolCluster.invalidSqlMode' , { sql_mode : options . sql_mode } )
78+ throw new Error ( `You cannot use any sql mode other than ${ mode } ` )
79+ } else {
80+ options . sql_mode = REQUIRED_SQL_MODES . join ( ',' )
81+ }
82+
83+ options . master . sql_mode = options . sql_mode
84+ options . slave . sql_mode = options . sql_mode
85+
86+
7087 // Use separate pools for master and slave connections.
7188 this . poolCluster . add ( 'MASTER' , options . master )
7289 this . poolCluster . add ( 'SLAVE' , options . slave )
@@ -1138,14 +1155,20 @@ module.exports = function (log, error) {
11381155 return resolve ( connection )
11391156 }
11401157
1141- connection . query ( 'SET NAMES utf8mb4 COLLATE utf8mb4_bin;' , ( err ) => {
1158+ var mode = REQUIRED_SQL_MODES . join ( ',' )
1159+ connection . query ( `SET SESSION sql_mode = '${ mode } ';` , ( err ) => {
11421160 if ( err ) {
11431161 return reject ( err )
11441162 }
11451163
1146- connection . _fxa_initialized = true
1164+ connection . query ( 'SET NAMES utf8mb4 COLLATE utf8mb4_bin;' , ( err ) => {
1165+ if ( err ) {
1166+ return reject ( err )
1167+ }
11471168
1148- resolve ( connection )
1169+ connection . _fxa_initialized = true
1170+ resolve ( connection )
1171+ } )
11491172 } )
11501173
11511174 } )
@@ -1247,7 +1270,8 @@ module.exports = function (log, error) {
12471270 'collation_server' ,
12481271 'max_connections' ,
12491272 'version' ,
1250- 'wait_timeout'
1273+ 'wait_timeout' ,
1274+ 'sql_mode'
12511275 ]
12521276
12531277 return this . getConnection ( poolName )
0 commit comments