@@ -10,40 +10,49 @@ const config = require('../config'),
10
10
var orm = { } ;
11
11
var sequelize ;
12
12
13
- // Instantiate a sequelize connection to an SQL database based on configuration
14
- // from server/config/env/*
15
- try {
16
- sequelize = new Sequelize ( config . orm . dbname , config . orm . user , config . orm . pass , config . orm . options ) ;
17
- } catch ( e ) {
18
- throw new Error ( e ) ;
19
- }
13
+ // Only read config.orm if it is defined, if not just return empty orm object
14
+ if ( config . orm ) {
20
15
21
- // Instantiate sequelize models
22
- config . files . server . sequelizeModels . forEach ( function ( modelPath ) {
16
+ // Instantiate a sequelize connection to an SQL database based on configuration
17
+ // from `server/config/env/*`
23
18
try {
24
- let model = sequelize . import ( path . resolve ( modelPath ) ) ;
25
- orm [ model . name ] = model ;
19
+ sequelize = new Sequelize ( config . orm . dbname , config . orm . user , config . orm . pass , config . orm . options ) ;
26
20
} catch ( e ) {
27
21
throw new Error ( e ) ;
28
22
}
29
- } ) ;
30
-
31
- // Once all models have been loaded, establish the associations between them
32
- Object . keys ( orm ) . forEach ( function ( modelName ) {
33
- if ( orm [ modelName ] . associate ) {
34
- orm [ modelName ] . associate ( orm ) ;
35
- }
36
- } ) ;
37
23
38
- // Expose the instantiated sequelize connection object
39
- orm . sequelize = sequelize ;
24
+ // Instantiate sequelize models
25
+ config . files . server . sequelizeModels . forEach ( function ( modelPath ) {
26
+ try {
27
+ let model = sequelize . import ( path . resolve ( modelPath ) ) ;
28
+ orm [ model . name ] = model ;
29
+ } catch ( e ) {
30
+ throw new Error ( e ) ;
31
+ }
32
+ } ) ;
33
+
34
+ // Once all models have been loaded, establish the associations between them
35
+ Object . keys ( orm ) . forEach ( function ( modelName ) {
36
+ if ( orm [ modelName ] . associate ) {
37
+ orm [ modelName ] . associate ( orm ) ;
38
+ }
39
+ } ) ;
40
+
41
+ // Expose the instantiated sequelize connection object
42
+ orm . sequelize = sequelize ;
43
+
44
+ // Expose the global Sequelize library
45
+ orm . Sequelize = Sequelize ;
46
+
47
+ orm . sync = function ( ) {
48
+ // Sync makes sure the database tables are created if they don't exist
49
+ // and the `force` parameter will also drop the tables before re-creating them
50
+ return this . sequelize . sync ( {
51
+ force : ( config . seedDB . reset || false )
52
+ } ) ;
53
+ } ;
40
54
41
- // Expose the global Sequelize library
42
- orm . Sequelize = Sequelize ;
43
-
44
- orm . sync = function ( ) {
45
- return this . sequelize . sync ( ) ;
46
- } ;
55
+ }
47
56
48
57
// Export this ORM module
49
58
module . exports = orm ;
0 commit comments