From b9e4b6484895e3c4cf35f54d7e3173ba503c2ac1 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 29 May 2014 15:45:25 -0700 Subject: [PATCH] Fix the varchar length --- lib/mysql.js | 3 ++- test/migration.test.js | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/mysql.js b/lib/mysql.js index a9b380d..f132ffa 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -973,7 +973,8 @@ function stringOptionsByType(p, dt) { switch (dt.toLowerCase()) { default: case 'varchar': - var len = p.limit || ((p.type !== String) ? 32768 : 1024); + // The maximum length for an ID column is 1000 bytes + var len = p.limit || ((p.type !== String) ? 32768 : p.id ? 255: 1024); dt += '(' + len + ')'; break; case 'char': diff --git a/test/migration.test.js b/test/migration.test.js index 4ae80ed..3746346 100644 --- a/test/migration.test.js +++ b/test/migration.test.js @@ -26,14 +26,14 @@ describe('migrations', function () { Extra: 'auto_increment' }, email: { Field: 'email', - Type: 'varchar(255)', + Type: 'varchar(1024)', Null: 'NO', Key: 'MUL', Default: null, Extra: '' }, name: { Field: 'name', - Type: 'varchar(255)', + Type: 'varchar(1024)', Null: 'YES', Key: '', Default: null, @@ -74,7 +74,6 @@ describe('migrations', function () { it('UserData should have correct indexes', function (done) { // Note: getIndexes truncates multi-key indexes to the first member. Hence index1 is correct. getIndexes('UserData', function (err, fields) { - // console.log('....', fields); assert.deepEqual(fields, { PRIMARY: { Table: 'UserData', Non_unique: 0, Key_name: 'PRIMARY', @@ -94,7 +93,7 @@ describe('migrations', function () { Column_name: 'email', Collation: 'A', Cardinality: null, - Sub_part: null, + Sub_part: 333, Packed: null, Null: '', Index_type: 'BTREE', @@ -106,7 +105,7 @@ describe('migrations', function () { Column_name: 'email', Collation: 'A', Cardinality: null, - Sub_part: null, + Sub_part: 333, Packed: null, Null: '', Index_type: 'BTREE',