From debf2762faf4604f3623d3868972118d1edd51f4 Mon Sep 17 00:00:00 2001 From: Scott Wyatt Date: Mon, 19 Oct 2020 14:31:43 -0500 Subject: [PATCH 1/5] fix(): fixes store.models migration selection --- lib/transformer.ts | 6 +++++- package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/transformer.ts b/lib/transformer.ts index e013faa..3751589 100755 --- a/lib/transformer.ts +++ b/lib/transformer.ts @@ -336,7 +336,11 @@ export const Transformer = { _sequelize[key] = Transformer.createConnectionsFromConfig(app, sequelize, key, stores[key], plugins) _sequelize[key].fabrixApp = app _sequelize[key].migrate = stores[key].migrate - _sequelize[key].models = {} + _sequelize[key].models = pickBy(app.models, (_model, name) => { + const modelConfig = _model.config + const store = modelConfig.store || app.config.get('models.defaultStore') + return store === key + }) }) return _sequelize diff --git a/package.json b/package.json index 236b72a..b2824b3 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": "1.6.18", + "version": "1.6.18.1", "description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com", "scripts": { "release": "standard-version", From 9420d4c7f781d5aedb39c6aded4439de8be0b98d Mon Sep 17 00:00:00 2001 From: Scott Wyatt Date: Mon, 19 Oct 2020 14:33:34 -0500 Subject: [PATCH 2/5] chore(release): 1.6.18.1 --- CHANGELOG.md | 7 +++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c31c7e9..19664c6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ 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.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.18](https://github.com/fabrix-app/spool-sequelize/compare/v1.6.17...v1.6.18) (2019-10-21) diff --git a/package-lock.json b/package-lock.json index 7ecbeaa..96c3adf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": "1.6.18", + "version": null, "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b2824b3..079ff70 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": "1.6.18.1", + "version": null, "description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com", "scripts": { "release": "standard-version", From 7c6c8841f806afed2b743f4e4a6393053edb6a1c Mon Sep 17 00:00:00 2001 From: Scott Wyatt Date: Mon, 19 Oct 2020 14:39:02 -0500 Subject: [PATCH 3/5] fix(): fixes broken version --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index df6a264..5e11bc6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": null, + "version": "1.6.18.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e3458b1..2a0a6c8 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": null, + "version": "1.6.18.1", "description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com", "scripts": { "release": "standard-version", From 3a4b71d8d46ac518d61aae3bff36d2678dd1001f Mon Sep 17 00:00:00 2001 From: Scott Wyatt Date: Mon, 19 Oct 2020 14:56:38 -0500 Subject: [PATCH 4/5] chore(release): 1.6.18.2 --- CHANGELOG.md | 7 +++ package-lock.json | 135 ++++++++++++++++++++++++++++++---------------- package.json | 4 +- 3 files changed, 98 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb12342..859da2a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ 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) diff --git a/package-lock.json b/package-lock.json index 5e11bc6..fe2bb7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": "1.6.18.1", + "version": null, "lockfileVersion": 1, "requires": true, "dependencies": { @@ -180,6 +180,11 @@ "winston": "^3.2.1" } }, + "@types/geojson": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-1.0.6.tgz", + "integrity": "sha512-Xqg/lIZMrUd0VRmSRbCAewtwGZiAk3mEUDvV4op1tGl+LvyPcb/MIOSxTl9z+9+J+R4/vpjiCAT4xeKzH9ji1w==" + }, "@types/lodash": { "version": "4.14.144", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.144.tgz", @@ -246,11 +251,6 @@ "color-convert": "^1.9.0" } }, - "any-promise": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", - "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8=" - }, "append-transform": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/append-transform/-/append-transform-1.0.0.tgz", @@ -376,9 +376,9 @@ } }, "bluebird": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.1.tgz", - "integrity": "sha512-DdmyoGCleJnkbp3nkbxTLJ18rjDsE4yCggEwKNXkeV123sPNfOCYeDoeuOY+F2FrSjO1YXcTU+dsy96KMy+gcg==" + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" }, "boom": { "version": "7.3.0", @@ -987,6 +987,7 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, "requires": { "ms": "^2.1.1" } @@ -1051,6 +1052,11 @@ "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", "dev": true }, + "depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + }, "detect-indent": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.0.0.tgz", @@ -1151,9 +1157,9 @@ } }, "dottie": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.1.tgz", - "integrity": "sha512-ch5OQgvGDK2u8pSZeSYAQaV/lczImd7pMJ7BcEPXmnFVjy4yJIzP6CsODJUTH8mg1tyH1Z2abOiuJO3DjZ/GBw==" + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.2.tgz", + "integrity": "sha512-fmrwR04lsniq/uSr8yikThDTrM7epXHBAAjH9TbeH3rEA8tdCO7mRzB9hdmdGyJCxF8KERo9CITcm3kGuoyMhg==" }, "ecc-jsbn": { "version": "0.1.2", @@ -1499,6 +1505,11 @@ } } }, + "generic-pool": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.5.0.tgz", + "integrity": "sha512-dEkxmX+egB2o4NR80c/q+xzLLzLX+k68/K8xv81XprD+Sk7ZtP14VugeCz+fUwv5FzpWq40pPtAkzPRqT8ka9w==" + }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -2727,14 +2738,14 @@ "dev": true }, "moment": { - "version": "2.24.0", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", - "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" + "version": "2.29.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz", + "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==" }, "moment-timezone": { - "version": "0.5.27", - "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.27.tgz", - "integrity": "sha512-EIKQs7h5sAsjhPCqN6ggx6cEbs94GK050254TIJySD1bzoM5JTYDwAU1IoVOeTOL6Gm27kYJ51/uuvq1kIlrbw==", + "version": "0.5.31", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.31.tgz", + "integrity": "sha512-+GgHNg8xRhMXfEbv81iDtrVeTcWt0kWmTEY1XQK14dICTXnWJnT0dxdlPspwqF3keKMVPXwayEsk1DI0AA/jdA==", "requires": { "moment": ">= 2.9.0" } @@ -3539,11 +3550,27 @@ "dev": true }, "retry-as-promised": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-3.2.0.tgz", - "integrity": "sha512-CybGs60B7oYU/qSQ6kuaFmRd9sTZ6oXSc0toqePvV74Ac6/IFZSI1ReFQmtCN+uvW1Mtqdwpvt/LGOiCBAY2Mg==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-2.3.2.tgz", + "integrity": "sha1-zZdO5P2bX+A8vzGHHuSCIcB3N7c=", "requires": { - "any-promise": "^1.3.0" + "bluebird": "^3.4.6", + "debug": "^2.6.9" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } } }, "rimraf": { @@ -3592,43 +3619,42 @@ "semver": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", - "dev": true + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" }, "sequelize": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.21.1.tgz", - "integrity": "sha512-JI+53MwcClfCFUPJT/l2dDzSpEzWAueyCZus33L/yhJxKTisfdd9OHrUPQ6/dI5nR5eIYT/EafrjkqTAlEQS2w==", + "version": "4.44.4", + "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-4.44.4.tgz", + "integrity": "sha512-nkHmYkbwQK7uwpgW9VBalCBnQqQ8mslTdgcBthtJLORuPvAYRPlfkXZMVUU9TLLJt9CX+/y0MYg0DpcP6ywsEQ==", "requires": { "bluebird": "^3.5.0", "cls-bluebird": "^2.1.0", - "debug": "^4.1.1", + "debug": "^3.1.0", + "depd": "^1.1.0", "dottie": "^2.0.0", + "generic-pool": "3.5.0", "inflection": "1.12.0", - "lodash": "^4.17.15", - "moment": "^2.24.0", - "moment-timezone": "^0.5.21", - "retry-as-promised": "^3.2.0", - "semver": "^6.3.0", - "sequelize-pool": "^2.3.0", + "lodash": "^4.17.1", + "moment": "^2.20.0", + "moment-timezone": "^0.5.14", + "retry-as-promised": "^2.3.2", + "semver": "^5.5.0", + "terraformer-wkt-parser": "^1.1.2", "toposort-class": "^1.0.1", - "uuid": "^3.3.3", - "validator": "^10.11.0", - "wkx": "^0.4.8" + "uuid": "^3.2.1", + "validator": "^10.4.0", + "wkx": "^0.4.1" }, "dependencies": { - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "debug": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", + "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "requires": { + "ms": "^2.1.1" + } } } }, - "sequelize-pool": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/sequelize-pool/-/sequelize-pool-2.3.0.tgz", - "integrity": "sha512-Ibz08vnXvkZ8LJTiUOxRcj1Ckdn7qafNZ2t59jYHMX1VIebTAOYefWdRYFt6z6+hy52WGthAHAoLc9hvk3onqA==" - }, "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", @@ -3996,6 +4022,23 @@ } } }, + "terraformer": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/terraformer/-/terraformer-1.0.12.tgz", + "integrity": "sha512-MokUp0+MFal4CmJDVL6VAO1bKegeXcBM2RnPVfqcFIp2IIv8EbPAjG0j/vEy/vuKB8NVMMSF2vfpVS/QLe4DBg==", + "requires": { + "@types/geojson": "^7946.0.0 || ^1.0.0" + } + }, + "terraformer-wkt-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/terraformer-wkt-parser/-/terraformer-wkt-parser-1.2.1.tgz", + "integrity": "sha512-+CJyNLWb3lJ9RsZMTM66BY0MT3yIo4l4l22Jd9CrZuwzk54fsu4Sc7zejuS9fCITTuTQy3p06d4MZMVI7v5wSg==", + "requires": { + "@types/geojson": "^1.0.0", + "terraformer": "~1.0.5" + } + }, "test-exclude": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-5.2.3.tgz", diff --git a/package.json b/package.json index 2a0a6c8..48820e0 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": "1.6.18.1", + "version": null, "description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com", "scripts": { "release": "standard-version", @@ -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", From 2326b7e60de6a51674127aeee9467c06460a25d8 Mon Sep 17 00:00:00 2001 From: Scott Wyatt Date: Mon, 19 Oct 2020 15:38:57 -0500 Subject: [PATCH 5/5] fix(): fixes localized migration --- lib/SequelizeResolver.ts | 3 +++ lib/api/services/SchemaMigrationService.ts | 12 ++++++------ lib/transformer.ts | 12 +++++++----- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/SequelizeResolver.ts b/lib/SequelizeResolver.ts index ca772b8..e97baba 100644 --- a/lib/SequelizeResolver.ts +++ b/lib/SequelizeResolver.ts @@ -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 diff --git a/lib/api/services/SchemaMigrationService.ts b/lib/api/services/SchemaMigrationService.ts index bf3aff1..f44e60c 100755 --- a/lib/api/services/SchemaMigrationService.ts +++ b/lib/api/services/SchemaMigrationService.ts @@ -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 @@ -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)] } diff --git a/lib/transformer.ts b/lib/transformer.ts index a4a486a..19995d9 100755 --- a/lib/transformer.ts +++ b/lib/transformer.ts @@ -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 }, @@ -367,13 +370,12 @@ 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 - _sequelize[key].models = pickBy(app.models, (_model, name) => { - const modelConfig = _model.config - const store = modelConfig.store || app.config.get('models.defaultStore') - return store === key - }) + // Declare models now, so that they are never undefined + _sequelize[key].models = {} }) return _sequelize diff --git a/package-lock.json b/package-lock.json index fe2bb7b..5fd1f5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": null, + "version": "1.6.18-3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 48820e0..e72454f 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-sequelize", - "version": null, + "version": "1.6.18-3", "description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com", "scripts": { "release": "standard-version",