Skip to content

Commit 2eefaa7

Browse files
committed
[refactor] trails/lib/*, add async to index.js.
Still needs to have the new store config added in.
1 parent 7c7c9aa commit 2eefaa7

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

api/services/FootprintService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const _ = require('lodash')
4-
const Service = require('trails/service')
4+
const Service = require('trails/lib/service')
55
const ModelError = require('../../lib').ModelError
66

77
const manageError = err => {

api/services/SchemaMigrationService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const Service = require('trails/service')
3+
const Service = require('trails/lib/service')
44

55
/**
66
* @module SchemaMigrationService

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = class SequelizeTrailpack extends Trailpack {
99
/**
1010
* Validate the database config, and api.model definitions
1111
*/
12-
validate() {
12+
async validate() {
1313
const stores = _.get(this.app.config, 'database.stores')
1414
if (stores && Object.keys(stores).length === 0) {
1515
this.app.config.log.logger.warn('No store configured at config.database.stores, models will be ignored')
@@ -41,7 +41,7 @@ module.exports = class SequelizeTrailpack extends Trailpack {
4141

4242
_.each(this.models, (model, modelName) => {
4343
_.each(this.connections, (connection, name) => {
44-
if (model.connection == name) {
44+
if (model.connection === name) {
4545
const Model = connection.define(modelName, model.schema, model.config)
4646

4747
if (model.config) {
@@ -78,7 +78,7 @@ module.exports = class SequelizeTrailpack extends Trailpack {
7878
/**
7979
* Close all database connections
8080
*/
81-
unload() {
81+
async unload() {
8282
return Promise.all(
8383
_.map(this.connections, connection => {
8484
return new Promise((resolve, reject) => {
@@ -89,19 +89,19 @@ module.exports = class SequelizeTrailpack extends Trailpack {
8989
)
9090
}
9191

92-
migrate() {
92+
async migrate() {
9393
const SchemaMigrationService = this.app.services.SchemaMigrationService
9494
const database = this.app.config.database
9595

96-
if (database.models.migrate == 'none') return
96+
if (database.models.migrate === 'none') return
9797

9898
return Promise.all(
9999
_.map(this.connections, connection => {
100100

101-
if (database.models.migrate == 'drop') {
101+
if (database.models.migrate === 'drop') {
102102
return SchemaMigrationService.dropDB(connection)
103103
}
104-
else if (database.models.migrate == 'alter') {
104+
else if (database.models.migrate === 'alter') {
105105
return SchemaMigrationService.alterDB(connection)
106106
}
107107
})

lib/transformer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint no-console: [0] */
2+
13
'use strict'
24
const _ = require('lodash')
35
const Sequelize = require('sequelize')
@@ -8,8 +10,10 @@ module.exports = {
810
* Augment the model definition with some sequelize-required properties
911
*/
1012
transformModels (app) {
13+
1114
const models = app.models
1215
const dbConfig = app.config.database
16+
1317
return _.mapValues(models, (model, modelName) => {
1418
const config = model.constructor.config(app, Sequelize) || {}
1519
const schema = model.constructor.schema(app, Sequelize) || {}

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
"email": "[email protected]",
99
"url": "https://github.com/jaumard"
1010
},
11+
"contributors": [
12+
{
13+
"name": "Scott Wyatt",
14+
"email": "[email protected]",
15+
"url": "https://github.com/scott-wyatt"
16+
}
17+
],
1118
"main": "index.js",
1219
"keywords": [
1320
"trailpack",
@@ -19,23 +26,23 @@
1926
"database"
2027
],
2128
"pre-commit": [
22-
"test"
29+
2330
],
2431
"dependencies": {
2532
"joi": "^10.6.0",
2633
"lodash": "^4.17.4",
2734
"sequelize": "^4.3.1",
2835
"snyk": "^1.36.2",
29-
"trailpack": "^2.1.2"
36+
"trailpack": "^3"
3037
},
3138
"devDependencies": {
3239
"eslint": "^4.2.0",
3340
"eslint-config-trails": "^3.0.0",
3441
"mocha": "^3.4.2",
3542
"pre-commit": "^1.2.2",
36-
"smokesignals": "^2.1.1",
43+
"smokesignals": "^3",
3744
"sqlite3": "^3.1.8",
38-
"trails": "^2.0.2"
45+
"trails": "^3"
3946
},
4047
"scripts": {
4148
"test": "eslint --fix . && mocha"

test/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const _ = require('lodash')
44
const smokesignals = require('smokesignals')
5-
const Model = require('trails/model')
5+
const Model = require('trails/lib/model')
66

77
module.exports = _.defaultsDeep({
88
pkg: {

0 commit comments

Comments
 (0)