diff --git a/lib/migration.js b/lib/migration.js index 6e69174a1..cf3944cbb 100644 --- a/lib/migration.js +++ b/lib/migration.js @@ -764,10 +764,12 @@ function mixinMigration(MySQL, mysql) { const colLength = columnMetadata && columnMetadata.dataLength || prop.length || prop.limit; const colPrecision = columnMetadata && columnMetadata.dataPrecision; const colScale = columnMetadata && columnMetadata.dataScale; + const colValue = columnMetadata && columnMetadata.value; // info on setting column specific properties // i.e dataLength, dataPrecision, dataScale // https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html if (colType) { + if (colValue) return colType + '(' + colValue + ')'; if (colLength) return colType + '(' + colLength + ')'; if (colPrecision && colScale) return colType + '(' + colPrecision + ',' + colScale + ')'; if (colPrecision) return colType + '(' + colPrecision + ')'; diff --git a/test/migration.test.js b/test/migration.test.js index 622f1e957..ee3dc227a 100644 --- a/test/migration.test.js +++ b/test/migration.test.js @@ -10,7 +10,7 @@ const platform = require('./helpers/platform'); const should = require('./init'); const Schema = require('loopback-datasource-juggler').Schema; -let db, UserData, StringData, NumberData, DateData, DefaultData, SimpleEmployee; +let db, UserData, StringData, NumberData, DateData, DefaultData, SimpleEmployee, SimplePatient; let mysqlVersion; describe('migrations', function() { @@ -32,6 +32,18 @@ describe('migrations', function() { }); }); + it('Migrating models that has enum', function(done) { + query('describe SimplePatient', function(err, result) { + should.not.exist(err); + should.exist(result); + result[0].Key.should.equal('PRI'); + result[0].Type.should.equal('bigint'); + result[2].Key.should.equal('type'); + result[2].Type.should.equal('enum(\'INPATIENT\',\'OUTPATIENT\')'); + done(); + }); + }); + it('UserData should have correct columns', function(done) { getFields('UserData', function(err, fields) { if (!fields) return done(); @@ -603,6 +615,12 @@ function setup(done) { name: {type: String}, }); + SimplePatient = db.define('SimplePatient', { + pid: {type: Number, generated: true, id: true, mysql: {dataType: 'bigint', dataLength: 20}}, + name: {type: String}, + patient: {type: String, mysql: {columnName: 'type', dataType: 'enum', value: "'INPATIENT','OUTPATIENT'", dataPrecision: null, dataScale: null, nullable: 'Y', generated: false}}, + }); + query('SELECT VERSION()', function(err, res) { mysqlVersion = res && res[0] && res[0]['VERSION()']; blankDatabase(db, done);