Merge pull request #43 from strongloop/feature/fix-default-length
Fix the default length for strings to avoid row size overflow
This commit is contained in:
commit
e0cb119e5f
12
lib/mysql.js
12
lib/mysql.js
|
@ -54,6 +54,14 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
|
|||
options.database = s.database;
|
||||
}
|
||||
|
||||
// Take other options for mysql driver
|
||||
// See https://github.com/strongloop/loopback-connector-mysql/issues/46
|
||||
for (var p in s) {
|
||||
if (options[p] === undefined) {
|
||||
options[p] = s[p];
|
||||
}
|
||||
}
|
||||
|
||||
dataSource.client = mysql.createPool(options);
|
||||
|
||||
dataSource.client.on('error', function (err) {
|
||||
|
@ -1027,11 +1035,11 @@ function stringOptionsByType(p, dt) {
|
|||
case 'varchar':
|
||||
// The maximum length for an ID column is 1000 bytes
|
||||
// The maximum row size is 64K
|
||||
var len = p.limit || ((p.type !== String) ? 8192 : p.id ? 255: 1024);
|
||||
var len = p.length || p.limit || ((p.type !== String) ? 4096 : p.id ? 255: 512);
|
||||
dt += '(' + len + ')';
|
||||
break;
|
||||
case 'char':
|
||||
len = p.limit || 255;
|
||||
len = p.length || p.limit || 255;
|
||||
dt += '(' + len + ')';
|
||||
break;
|
||||
|
||||
|
|
|
@ -26,14 +26,14 @@ describe('migrations', function () {
|
|||
Extra: 'auto_increment' },
|
||||
email: {
|
||||
Field: 'email',
|
||||
Type: 'varchar(1024)',
|
||||
Type: 'varchar(512)',
|
||||
Null: 'NO',
|
||||
Key: 'MUL',
|
||||
Default: null,
|
||||
Extra: '' },
|
||||
name: {
|
||||
Field: 'name',
|
||||
Type: 'varchar(1024)',
|
||||
Type: 'varchar(512)',
|
||||
Null: 'YES',
|
||||
Key: '',
|
||||
Default: null,
|
||||
|
|
Loading…
Reference in New Issue