File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -770,10 +770,21 @@ function mixinMigration(MySQL, mysql) {
770770 const colLength = columnMetadata && columnMetadata . dataLength || prop . length || prop . limit ;
771771 const colPrecision = columnMetadata && columnMetadata . dataPrecision ;
772772 const colScale = columnMetadata && columnMetadata . dataScale ;
773+ let enumList = '' ;
774+ if ( colType && colType === 'ENUM' ) {
775+ if ( prop . jsonSchema && prop . jsonSchema . enum ) {
776+ prop . jsonSchema . enum . forEach ( item => {
777+ enumList += `'${ item } ',` ;
778+ } ) ;
779+ // remove trailing comma
780+ enumList = enumList . substring ( 0 , enumList . length - 1 ) ;
781+ }
782+ }
773783 // info on setting column specific properties
774784 // i.e dataLength, dataPrecision, dataScale
775785 // https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html
776786 if ( colType ) {
787+ if ( colType === 'ENUM' ) return colType + '(' + enumList + ')' ;
777788 if ( colLength ) return colType + '(' + colLength + ')' ;
778789 if ( colPrecision && colScale ) return colType + '(' + colPrecision + ',' + colScale + ')' ;
779790 if ( colPrecision ) return colType + '(' + colPrecision + ')' ;
Original file line number Diff line number Diff line change @@ -85,6 +85,13 @@ describe('migrations', function() {
8585 Key : '' ,
8686 Default : null ,
8787 Extra : '' } ,
88+ typings : {
89+ Field : 'typings' ,
90+ Type : "enum('A','B')" ,
91+ Null : 'YES' ,
92+ Key : '' ,
93+ Default : null ,
94+ Extra : '' } ,
8895 } ) ;
8996 done ( ) ;
9097 } ) ;
@@ -548,9 +555,10 @@ function setup(done) {
548555 require ( './init.js' ) ;
549556
550557 db = global . getSchema ( ) ;
551-
558+ const customType = db . EnumFactory ( 'A' , 'B' ) ;
552559 UserData = db . define ( 'UserData' , {
553560 email : { type : String , null : false , index : true } ,
561+ typings : { type : customType } ,
554562 name : String ,
555563 bio : Schema . Text ,
556564 birthDate : Date ,
You can’t perform that action at this time.
0 commit comments