Skip to content

Commit 3e1d7a9

Browse files
jaumardjaumard
authored andcommitted
migrate to v3
1 parent 7c7c9aa commit 3e1d7a9

File tree

10 files changed

+355
-312
lines changed

10 files changed

+355
-312
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
language: node_js
22
node_js:
3-
- 4
4-
- 5
5-
- 6
63
- 7
4+
- 8
5+
- 9
76

87
notifications:
98
email: false
@@ -21,4 +20,4 @@ deploy:
2120
on:
2221
tags: true
2322
repo: trailsjs/trailpack-sequelize
24-
node: 7
23+
node: 8

api/services/FootprintService.js

Lines changed: 2 additions & 2 deletions
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 => {
@@ -39,7 +39,7 @@ module.exports = class FootprintService extends Service {
3939
*/
4040
create(modelName, values, options) {
4141
const Model = this._getModel(modelName)
42-
const modelOptions = _.defaultsDeep({}, options, _.get(this.app.config, 'footprints.models.options'))
42+
const modelOptions = _.defaultsDeep({}, options, this.app.config.get('footprints.models.options'))
4343
if (!Model) {
4444
return Promise.reject(new ModelError('E_NOT_FOUND', `${modelName} can't be found`))
4545
}

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ module.exports = class SequelizeTrailpack extends Trailpack {
9191

9292
migrate() {
9393
const SchemaMigrationService = this.app.services.SchemaMigrationService
94-
const database = this.app.config.database
94+
const migrate = this.app.config.get('database.models.migrate')
9595

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

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

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

lib/transformer.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module.exports = {
99
*/
1010
transformModels (app) {
1111
const models = app.models
12-
const dbConfig = app.config.database
1312
return _.mapValues(models, (model, modelName) => {
1413
const config = model.constructor.config(app, Sequelize) || {}
1514
const schema = model.constructor.schema(app, Sequelize) || {}
@@ -26,8 +25,8 @@ module.exports = {
2625
identity: modelName.toLowerCase(),
2726
globalId: modelName,
2827
tableName: config.tableName || modelName.toLowerCase(),
29-
connection: config.store || dbConfig.models.defaultStore,
30-
migrate: config.migrate || dbConfig.models.migrate,
28+
connection: config.store || app.config.get('database.models.defaultStore'),
29+
migrate: config.migrate || app.config.get('database.models.migrate'),
3130
config: config.options,
3231
schema: schema
3332
}
@@ -68,7 +67,7 @@ module.exports = {
6867
* Transform the Trails.js "stores" config into a Sequelize object
6968
*/
7069
transformStores (app) {
71-
const stores = this.pickStores(app.config.database.stores)
70+
const stores = this.pickStores(app.config.get('database.stores'))
7271
const sequelize = {}
7372
Object.keys(stores).forEach(key => {
7473
sequelize[key] = this.createFromConfig(stores[key])

package.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "trailpack-sequelize",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"description": "Sequelize.js Trailpack http://sequelizejs.com",
55
"homepage": "https://github.com/jaumard/trailpack-sequelize",
66
"author": {
@@ -22,26 +22,29 @@
2222
"test"
2323
],
2424
"dependencies": {
25-
"joi": "^10.6.0",
25+
"joi": "^12.0.0",
2626
"lodash": "^4.17.4",
27-
"sequelize": "^4.3.1",
28-
"snyk": "^1.36.2",
29-
"trailpack": "^2.1.2"
27+
"sequelize": "^4.23.0",
28+
"snyk": "^1.50.0",
29+
"trailpack": "^3.0.0"
3030
},
3131
"devDependencies": {
32-
"eslint": "^4.2.0",
32+
"eslint": "^4.11.0",
3333
"eslint-config-trails": "^3.0.0",
34-
"mocha": "^3.4.2",
34+
"mocha": "^4.0.1",
3535
"pre-commit": "^1.2.2",
36-
"smokesignals": "^2.1.1",
37-
"sqlite3": "^3.1.8",
38-
"trails": "^2.0.2"
36+
"smokesignals": "^3.0.4",
37+
"sqlite3": "^3.1.13",
38+
"trails": "^3.0.3"
39+
},
40+
"peerDependencies": {
41+
"trails": "3.x"
3942
},
4043
"scripts": {
4144
"test": "eslint --fix . && mocha"
4245
},
4346
"engines": {
44-
"node": ">= 4.0.0"
47+
"node": ">= 7.0.0"
4548
},
4649
"eslintConfig": {
4750
"extends": "trails"

test/app.js

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

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

76
module.exports = _.defaultsDeep({
87
pkg: {

test/lib/sequelize.callbacks.test.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ describe('lib.Transformer.SequelizeCallbacks', () => {
2424
describe('#afterCreate', () => {
2525
it('should create a record with afterCreate attribute set', () => {
2626
//FootprintService.destroy('ModelCallbacks',{})
27-
return FootprintService.create('ModelCallbacks', {name: 'trails_afterCreate', beforeValidate: 0, afterCreate: 0})
27+
return FootprintService.create('ModelCallbacks', {
28+
name: 'trails_afterCreate',
29+
beforeValidate: 0,
30+
afterCreate: 0
31+
})
2832
.then(record => {
2933
assert.equal(record.afterCreate, 1)
3034
})
@@ -40,13 +44,13 @@ describe('lib.Transformer.SequelizeCallbacks', () => {
4044
.then(record => {
4145
return FootprintService.update(
4246
'ModelCallbacks',
43-
{name: 'trails_beforeUpdate'},
44-
{name: 'trails_UpdatedBefore', beforeValidate: 0, beforeUpdate: 0}
47+
{ name: 'trails_beforeUpdate' },
48+
{ name: 'trails_UpdatedBefore', beforeValidate: 0, beforeUpdate: 0 }
4549
)
4650
})
4751
.then(records => {
4852
assert.equal(records[0], 1)
49-
return FootprintService.find('ModelCallbacks', {name: 'trails_UpdatedBefore'})
53+
return FootprintService.find('ModelCallbacks', { name: 'trails_UpdatedBefore' })
5054
})
5155
.then(records => {
5256
assert.equal(records[0].beforeUpdate, 1)
@@ -55,17 +59,17 @@ describe('lib.Transformer.SequelizeCallbacks', () => {
5559
})
5660
describe('#afterUpdate', () => {
5761
it.skip('afterUpdate should be called', () => {
58-
return FootprintService.create('ModelCallbacks', {name: 'trails_afterUpdate', beforeValidate: 0})
62+
return FootprintService.create('ModelCallbacks', { name: 'trails_afterUpdate', beforeValidate: 0 })
5963
.then(record => {
6064
return FootprintService.update(
6165
'ModelCallbacks',
62-
{name: 'trails_afterUpdate'},
63-
{name: 'trails_UpdatedAfter', beforeValidate: 0, afterUpdate: 0}
66+
{ name: 'trails_afterUpdate' },
67+
{ name: 'trails_UpdatedAfter', beforeValidate: 0, afterUpdate: 0 }
6468
)
6569
})
6670
.then(results => {
6771
assert.equal(results[0], 1)
68-
return FootprintService.find('ModelCallbacks', {name: 'trails_UpdatedAfter'})
72+
return FootprintService.find('ModelCallbacks', { name: 'trails_UpdatedAfter' })
6973
})
7074
.then(records => {
7175
assert.equal(records[0].afterUpdate, 1)
@@ -74,7 +78,7 @@ describe('lib.Transformer.SequelizeCallbacks', () => {
7478
})
7579
describe('#beforeValidate', () => {
7680
it('should create a record with a beforeValidate attribute', () => {
77-
return FootprintService.create('ModelCallbacks', {name: 'trails_beforeCreate', beforeValidate: 0})
81+
return FootprintService.create('ModelCallbacks', { name: 'trails_beforeCreate', beforeValidate: 0 })
7882
.then(record => {
7983
assert.equal(record.beforeValidate, 1)
8084
})
@@ -94,12 +98,12 @@ describe('lib.Transformer.SequelizeCallbacks', () => {
9498
})
9599
describe('#beforeDestroy', () => {
96100
it('should call the beforeDestroy callback and continue', () => {
97-
return FootprintService.create('ModelCallbacks', {name: 'trails_beforeDestroy', beforeValidate: 0})
101+
return FootprintService.create('ModelCallbacks', { name: 'trails_beforeDestroy', beforeValidate: 0 })
98102
.then(record => {
99-
return FootprintService.destroy('ModelCallbacks', {name: 'trails_beforeDestroy'})
103+
return FootprintService.destroy('ModelCallbacks', { name: 'trails_beforeDestroy' })
100104
})
101105
.then(records => {
102-
return FootprintService.find('ModelCallbacks', {name: 'trails_beforeDestroy'})
106+
return FootprintService.find('ModelCallbacks', { name: 'trails_beforeDestroy' })
103107
})
104108
.then(records => {
105109
assert.equal(records.length, 0)
@@ -108,12 +112,12 @@ describe('lib.Transformer.SequelizeCallbacks', () => {
108112
})
109113
describe('#afterDestroy', () => {
110114
it('should call the afterDestroy callback and continue', () => {
111-
return FootprintService.create('ModelCallbacks', {name: 'trails_afterDestroy', beforeValidate: 0})
115+
return FootprintService.create('ModelCallbacks', { name: 'trails_afterDestroy', beforeValidate: 0 })
112116
.then(record => {
113-
return FootprintService.destroy('ModelCallbacks', {name: 'trails_afterDestroy'})
117+
return FootprintService.destroy('ModelCallbacks', { name: 'trails_afterDestroy' })
114118
})
115119
.then(records => {
116-
return FootprintService.find('ModelCallbacks', {name: 'trails_afterDestroy'})
120+
return FootprintService.find('ModelCallbacks', { name: 'trails_afterDestroy' })
117121
})
118122
.then(records => {
119123
assert.equal(records.length, 0)

test/services/FootprintService.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ describe('api.services.FootprintService', () => {
3434
return FootprintService.create('User', {roles: [{name: 'roleTest'}]}, {populate: 'roles'})
3535
.catch(err => {
3636
assert.equal(err.code, 'E_VALIDATION')
37-
assert.equal(err.message, 'notNull Violation: name cannot be null')
37+
assert.equal(err.message, 'notNull Violation: User.name cannot be null')
3838
assert.equal(err.errors[0].path, 'name')
39-
assert.equal(err.errors[0].message, 'name cannot be null')
39+
assert.equal(err.errors[0].message, 'User.name cannot be null')
4040
assert.equal(err.errors[0].type, 'notNull Violation')
4141
assert.equal(err.name, 'Model error')
4242
})

0 commit comments

Comments
 (0)