Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(): fixes store.models migration selection #60

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.6.18.2](https://github.com/fabrix-app/spool-sequelize/compare/v1.6.20...v1.6.18.2) (2020-10-19)


### Bug Fixes

* fixes broken version ([7c6c884](https://github.com/fabrix-app/spool-sequelize/commit/7c6c8841f806afed2b743f4e4a6393053edb6a1c))
* fixes store.models migration selection ([debf276](https://github.com/fabrix-app/spool-sequelize/commit/debf2762faf4604f3623d3868972118d1edd51f4))

## [1.6.18.1](https://github.com/fabrix-app/spool-sequelize/compare/v1.6.18...v1.6.18.1) (2020-10-19)


### Bug Fixes

* fixes store.models migration selection ([debf276](https://github.com/fabrix-app/spool-sequelize/commit/debf2762faf4604f3623d3868972118d1edd51f4))

### [1.6.20](https://github.com/fabrix-app/spool-sequelize/compare/v1.6.19...v1.6.20) (2019-10-24)

### [1.6.19](https://github.com/fabrix-app/spool-sequelize/compare/v1.6.18...v1.6.19) (2019-10-24)


### [1.6.18](https://github.com/fabrix-app/spool-sequelize/compare/v1.6.17...v1.6.18) (2019-10-21)


Expand All @@ -29,4 +45,4 @@ Add better validation errors for Footprints
Return not found error if model is not found

## v0.0.3
Initial version
Initial version
3 changes: 3 additions & 0 deletions lib/SequelizeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export class SequelizeResolver extends FabrixResolver {
this._sequelizeModel.app = this.app
// this._sequelizeModel.model = this.model

// Set the config for migrate on the sequelize model
this._sequelizeModel.migrate = this.model.migrate

// A helpful exposure of the instance of Sequelize being used
this._sequelize = this._sequelizeModel.sequelize
this.model.datastore = this.model['sequelize'] = this.datastore
Expand Down
12 changes: 6 additions & 6 deletions lib/api/services/SchemaMigrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ export class SchemaMigrationService extends Service {
migrateModels(models, connection) {
let promises = []
Object.entries(models).forEach(([ _, model ]: [ any, {[key: string]: any}]) => {

console.log('BRK MODEL MIGRATE', _, model.migrate)

if (model.migrate === 'drop') {
promises.push(this.dropModel(model, connection))
}
else if (model.migrate === 'alter') {
promises.push(this.alterModel(model, connection))
}
else if (model.migrate === 'none') {
return
else if (model.migrate === 'none' || model.migrate === 'safe') {
// placeholders
}
else {
return
// placeholders
}
})
return promises
Expand Down Expand Up @@ -89,9 +92,6 @@ export class SchemaMigrationService extends Service {
else if (store.migrate === 'alter') {
promises.push(this.alterDB(store))
}
else if (store.migrate === 'none') {
return
}
else {
promises = [...promises, ...this.migrateModels(store.models, store)]
}
Expand Down
6 changes: 6 additions & 0 deletions lib/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ export const Transformer = {
model.resolver.connection = connection
model.resolver.connect(modelName, schema, options)

// Assign the model to the connection models
// connection.models[modelName] = model

return model
},

Expand Down Expand Up @@ -367,8 +370,11 @@ export const Transformer = {
const _sequelize = {}
Object.keys(stores).forEach(key => {
_sequelize[key] = Transformer.createConnectionsFromConfig(app, sequelize, key, stores[key], plugins)
// Set fabrix to the store
_sequelize[key].fabrixApp = app
// Add the migrate onto the store
_sequelize[key].migrate = stores[key].migrate
// Declare models now, so that they are never undefined
_sequelize[key].models = {}
})

Expand Down
135 changes: 89 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/spool-sequelize",
"version": "1.6.20",
"version": "1.6.18-3",
"description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com",
"scripts": {
"release": "standard-version",
Expand Down Expand Up @@ -55,7 +55,7 @@
"joi": "^14.3.1",
"lodash": "^4.17.15",
"merge-options": "^2.0.0",
"sequelize": "^5.21.1"
"sequelize": "^4.43.0"
},
"devDependencies": {
"@fabrix/fabrix": "^1.6.4",
Expand Down