fix: add values to enum type
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
This commit is contained in:
parent
55ef653820
commit
a8d04452d1
|
@ -764,10 +764,12 @@ function mixinMigration(MySQL, mysql) {
|
||||||
const colLength = columnMetadata && columnMetadata.dataLength || prop.length || prop.limit;
|
const colLength = columnMetadata && columnMetadata.dataLength || prop.length || prop.limit;
|
||||||
const colPrecision = columnMetadata && columnMetadata.dataPrecision;
|
const colPrecision = columnMetadata && columnMetadata.dataPrecision;
|
||||||
const colScale = columnMetadata && columnMetadata.dataScale;
|
const colScale = columnMetadata && columnMetadata.dataScale;
|
||||||
|
const colValue = columnMetadata && columnMetadata.value;
|
||||||
// info on setting column specific properties
|
// info on setting column specific properties
|
||||||
// i.e dataLength, dataPrecision, dataScale
|
// i.e dataLength, dataPrecision, dataScale
|
||||||
// https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html
|
// https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html
|
||||||
if (colType) {
|
if (colType) {
|
||||||
|
if (colValue) return colType + '(' + colValue + ')';
|
||||||
if (colLength) return colType + '(' + colLength + ')';
|
if (colLength) return colType + '(' + colLength + ')';
|
||||||
if (colPrecision && colScale) return colType + '(' + colPrecision + ',' + colScale + ')';
|
if (colPrecision && colScale) return colType + '(' + colPrecision + ',' + colScale + ')';
|
||||||
if (colPrecision) return colType + '(' + colPrecision + ')';
|
if (colPrecision) return colType + '(' + colPrecision + ')';
|
||||||
|
|
|
@ -10,7 +10,7 @@ const platform = require('./helpers/platform');
|
||||||
const should = require('./init');
|
const should = require('./init');
|
||||||
const Schema = require('loopback-datasource-juggler').Schema;
|
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;
|
let mysqlVersion;
|
||||||
|
|
||||||
describe('migrations', function() {
|
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].Field.should.equal('type');
|
||||||
|
result[2].Type.should.equal('enum(\'INPATIENT\',\'OUTPATIENT\')');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('UserData should have correct columns', function(done) {
|
it('UserData should have correct columns', function(done) {
|
||||||
getFields('UserData', function(err, fields) {
|
getFields('UserData', function(err, fields) {
|
||||||
if (!fields) return done();
|
if (!fields) return done();
|
||||||
|
@ -603,6 +615,23 @@ function setup(done) {
|
||||||
name: {type: String},
|
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) {
|
query('SELECT VERSION()', function(err, res) {
|
||||||
mysqlVersion = res && res[0] && res[0]['VERSION()'];
|
mysqlVersion = res && res[0] && res[0]['VERSION()'];
|
||||||
blankDatabase(db, done);
|
blankDatabase(db, done);
|
||||||
|
|
Loading…
Reference in New Issue