@@ -11,7 +11,7 @@ module.exports = sails => {
1111 exposeToGlobal : true
1212 }
1313 } ,
14- configure ( ) {
14+ configure ( ) {
1515 const cls = sails . config [ this . configKey ] . clsNamespace ;
1616 // If custom log function is specified, use it for SQL logging or use sails logger of defined level
1717 if ( typeof cls === 'string' && cls !== '' ) {
@@ -25,7 +25,7 @@ module.exports = sails => {
2525
2626 // Override sails internal loadModels function
2727 // needs to be done in configure()
28- sails . modules . loadModels = function load ( cb ) {
28+ sails . modules . loadModels = function load ( cb ) {
2929
3030 // call the original sails loadModels function so we have access to it's returned models
3131 originalLoadModels ( ( err , modelDefs ) => {
@@ -48,7 +48,7 @@ module.exports = sails => {
4848 } ) ;
4949 } ;
5050 } ,
51- initialize ( next ) {
51+ initialize ( next ) {
5252
5353 if ( sails . config . hooks . orm === false ) {
5454 this . initAdapters ( ) ;
@@ -65,7 +65,7 @@ module.exports = sails => {
6565 }
6666 } ,
6767
68- reload ( next ) {
68+ reload ( next ) {
6969 let connections ;
7070 const self = this ;
7171
@@ -95,13 +95,13 @@ module.exports = sails => {
9595 } ) ;
9696 } ,
9797
98- initAdapters ( ) {
98+ initAdapters ( ) {
9999 if ( typeof ( sails . adapters ) === 'undefined' ) {
100100 sails . adapters = { } ;
101101 }
102102 } ,
103103
104- initConnections ( ) {
104+ initConnections ( ) {
105105 const connections = { } ;
106106 let connection , connectionName ;
107107
@@ -112,15 +112,15 @@ module.exports = sails => {
112112 const datastoreName = sails . config . models . connection || sails . config . models . datastore || 'default' ;
113113
114114 sails . log . verbose ( 'Using default connection named ' + datastoreName ) ;
115- if ( ! datastores . hasOwnProperty ( datastoreName ) ) {
115+ if ( ! Object . prototype . hasOwnProperty . call ( datastores , datastoreName ) ) {
116116 throw new Error ( 'Default connection \'' + datastoreName + '\' not found in config/connections' ) ;
117117 }
118118
119119 for ( connectionName in datastores ) {
120120 connection = datastores [ connectionName ] ;
121121
122- // Skip waterline connections
123- if ( connection . adapter ) {
122+ // Skip waterline and possible non sequelize connections
123+ if ( connection . adapter || ! ( connection . dialect || connection . options . dialect ) ) {
124124 continue ;
125125 }
126126
@@ -146,13 +146,13 @@ module.exports = sails => {
146146 return connections ;
147147 } ,
148148
149- initModels ( ) {
149+ initModels ( ) {
150150 if ( typeof ( sails . models ) === 'undefined' ) {
151151 sails . models = { } ;
152152 }
153153 } ,
154154
155- defineModels ( models , connections ) {
155+ defineModels ( models , connections ) {
156156 let modelDef , modelName , modelClass , cm , im , connectionName ;
157157 const sequelizeMajVersion = parseInt ( Sequelize . version . split ( '.' ) [ 0 ] , 10 ) ;
158158
@@ -171,7 +171,9 @@ module.exports = sails => {
171171
172172 sails . log . verbose ( 'Loading Sequelize model \'' + modelDef . globalId + '\'' ) ;
173173 connectionName = modelDef . connection || modelDef . datastore || defaultConnection ;
174- modelClass = connections [ connectionName ] . define ( modelDef . globalId , modelDef . attributes , modelDef . options ) ;
174+ modelClass = connections [ connectionName ] . define ( modelDef . globalId ,
175+ modelDef . attributes ,
176+ modelDef . options ) ;
175177
176178 if ( sequelizeMajVersion >= 4 ) {
177179 for ( cm in modelDef . options . classMethods ) {
@@ -203,7 +205,7 @@ module.exports = sails => {
203205 }
204206 } ,
205207
206- setAssociation ( modelDef ) {
208+ setAssociation ( modelDef ) {
207209 if ( modelDef . associations !== null ) {
208210 sails . log . verbose ( 'Loading associations for \'' + modelDef . globalId + '\'' ) ;
209211 if ( typeof modelDef . associations === 'function' ) {
@@ -212,7 +214,7 @@ module.exports = sails => {
212214 }
213215 } ,
214216
215- setDefaultScope ( modelDef , model ) {
217+ setDefaultScope ( modelDef , model ) {
216218 if ( modelDef . defaultScope !== null ) {
217219 sails . log . verbose ( 'Loading default scope for \'' + modelDef . globalId + '\'' ) ;
218220 if ( typeof modelDef . defaultScope === 'function' ) {
@@ -222,8 +224,8 @@ module.exports = sails => {
222224 }
223225 } ,
224226
225- migrateSchema ( next , connections , models ) {
226- let connectionDescription , connectionName , migrate , forceSyncFlag , alterFlag ;
227+ migrateSchema ( next , connections , models ) {
228+ let connectionDescription , cn , migrate , forceSyncFlag , alterFlag ;
227229 const syncTasks = [ ] ;
228230
229231 // Try to read settings from old Sails then from the new.
@@ -251,13 +253,14 @@ module.exports = sails => {
251253 alterFlag = false ;
252254 }
253255
254- for ( connectionName in datastores ) {
255- ( function ( ) {
256+ for ( cn in datastores ) {
257+ ( function ( connectionName ) {
256258 var syncConnectionName = connectionName ;
257259 connectionDescription = datastores [ syncConnectionName ] ;
258260
259- // Skip waterline connections
260- if ( connectionDescription . adapter ) {
261+ // Skip waterline and possible non sequelize connections
262+ if ( connectionDescription . adapter ||
263+ ! ( connectionDescription . dialect || connectionDescription . options . dialect ) ) {
261264 return ;
262265 }
263266
@@ -277,14 +280,17 @@ module.exports = sails => {
277280 schemas . push ( tableSchema ) ;
278281 }
279282 }
280-
283+ console . log ( 'migrateSchema in ' + syncConnectionName ) ;
281284 return connections [ syncConnectionName ] . sync ( { force : forceSyncFlag , alter : alterFlag } ) ;
282285 } ) ) ;
283286
284287 } else {
285- syncTasks . push ( connections [ syncConnectionName ] . sync ( { force : forceSyncFlag , alter : alterFlag } ) ) ;
288+ syncTasks . push ( connections [ syncConnectionName ] . sync ( {
289+ force : forceSyncFlag ,
290+ alter : alterFlag
291+ } ) ) ;
286292 }
287- } ( ) ) ;
293+ } ( cn ) ) ;
288294 }
289295
290296 Promise . all ( syncTasks ) . then ( ( ) => next ( ) ) . catch ( e => next ( e ) ) ;
0 commit comments