diff --git a/README.md b/README.md index ebca5e9c81a..10b13f06e86 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,6 @@ Is there anything else you’d like to see in Compass? Let us know by submitting - [**@mongodb-js/mongodb-notary-service-client**](packages/notary-service-client): A client for our notary-service: an API for codesigning - [**@mongodb-js/mongodb-redux-common**](packages/redux-common): Common Redux Modules for mongodb-js - [**@mongodb-js/ssh-tunnel**](packages/ssh-tunnel): Yet another ssh tunnel based on ssh2 -- [**app-migrations**](packages/app-migrations): Helper for application schema migrations - [**bson-transpilers**](packages/bson-transpilers): Source to source compilers using ANTLR - [**compass-e2e-tests**](packages/compass-e2e-tests): E2E test suite for Compass app that follows smoke tests / feature testing matrix - [**compass-preferences-model**](packages/compass-preferences-model): Compass preferences model diff --git a/package-lock.json b/package-lock.json index 8e3d44ddb2f..e4cb3d97cdb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15882,10 +15882,6 @@ "resolved": "https://registry.npmjs.org/antlr4/-/antlr4-4.7.2.tgz", "integrity": "sha512-vZA1xYufXLe3LX+ja9rIVxjRmILb1x3k7KYZHltRbfJtXjJ1DlFIqt+CbPYmghx0EuzY9DajiDw+MdyEt1qAsQ==" }, - "node_modules/app-migrations": { - "resolved": "packages/app-migrations", - "link": true - }, "node_modules/appdmg": { "version": "0.6.4", "resolved": "https://registry.npmjs.org/appdmg/-/appdmg-0.6.4.tgz", @@ -42733,7 +42729,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", - "dev": true + "devOptional": true }, "node_modules/why-is-node-running": { "version": "2.2.2", @@ -43363,6 +43359,7 @@ }, "packages/app-migrations": { "version": "3.2.1", + "extraneous": true, "license": "SSPL", "dependencies": { "@mongodb-js/compass-logging": "^1.2.1", @@ -69451,20 +69448,6 @@ "resolved": "https://registry.npmjs.org/antlr4/-/antlr4-4.7.2.tgz", "integrity": "sha512-vZA1xYufXLe3LX+ja9rIVxjRmILb1x3k7KYZHltRbfJtXjJ1DlFIqt+CbPYmghx0EuzY9DajiDw+MdyEt1qAsQ==" }, - "app-migrations": { - "version": "file:packages/app-migrations", - "requires": { - "@mongodb-js/compass-logging": "^1.2.1", - "async": "^3.2.2", - "debug": "^4.2.0", - "depcheck": "^1.4.1", - "eslint": "^7.25.0", - "eslint-config-mongodb-js": "^5.0.3", - "lodash": "^4.17.21", - "mocha": "^10.2.0", - "semver": "^7.5.4" - } - }, "appdmg": { "version": "0.6.4", "resolved": "https://registry.npmjs.org/appdmg/-/appdmg-0.6.4.tgz", @@ -93155,7 +93138,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", - "dev": true + "devOptional": true }, "why-is-node-running": { "version": "2.2.2", diff --git a/packages/app-migrations/.depcheckrc b/packages/app-migrations/.depcheckrc deleted file mode 100644 index 8bb6edae487..00000000000 --- a/packages/app-migrations/.depcheckrc +++ /dev/null @@ -1 +0,0 @@ -ignores: [] diff --git a/packages/app-migrations/.eslintrc b/packages/app-migrations/.eslintrc deleted file mode 100644 index 9493cc419ce..00000000000 --- a/packages/app-migrations/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": ["mongodb-js/node"] -} diff --git a/packages/app-migrations/.gitignore b/packages/app-migrations/.gitignore deleted file mode 100644 index 153216eb946..00000000000 --- a/packages/app-migrations/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.DS_Store -node_modules/ -npm-debug.log diff --git a/packages/app-migrations/.npmignore b/packages/app-migrations/.npmignore deleted file mode 100644 index e69887256e4..00000000000 --- a/packages/app-migrations/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -.eslintrc -.travis.yml -test/ -examples/ diff --git a/packages/app-migrations/README.md b/packages/app-migrations/README.md deleted file mode 100644 index 4bd695519b6..00000000000 --- a/packages/app-migrations/README.md +++ /dev/null @@ -1,96 +0,0 @@ -# app-migrations [![npm][npm_img]][npm_url] - -> A helper module to define and execute app schema migrations. - -Run on every start of your application with the previous and current version. - -Makes sure that the correct migration steps are executed in the right order and -that downgrades are only allowed if there hasn't been a migration between the -two versions. - -app-migrations uses [semver](https://github.com/npm/node-semver) to determine -version order. - -## Examples - -##### Set up migrations - -```javascript -// define your migrations functions, keyed to the version they were introduced at. -var migrations = { - '1.0.4': function(previousVersion, currentVersion, done) { - // introduced new "jetpack" feature which requires changes to the engine. - // ... add code here ... - done(null, 'upgraded engine to support jetpack.'); - }, - '1.0.9': function(previousVersion, currentVersion, done) { - // added photon cannons for more fire power, but needed to deprecate - // laser cannons instead. - // ... add code here ... - done(null, 'removed laser cannons, added photon cannons.'); - } -}; - -var migrate = require('app-migrations')(migrations); -``` -On every new launch, run `migrate()` with previous and current version. - -##### upgrade from 1.0.0 (got nothing) to 2.0.0 (need jetpack and photon cannons) - -```javascript -migrate('1.0.0', '2.0.0', function(err, res) { - if (err) return console.error('Error:', e.message); - console.log('Success:', res); -}); - -// console output -// Success: { '1.0.4': 'upgraded engine to support jetpack.', -// '1.0.9': 'removed laser cannons, added photon cannons.' } -``` - -##### upgrade from 1.0.5 (we already got jetpacks) to 1.1.4 (need photon cannon) -```javascript -migrate('1.0.5', '1.1.4', function(err, res) { - if (err) return console.error('Error:', e.message); - console.log('Success:', res); -}); - -// console output -// Success: { '1.0.9': 'removed laser cannons, added photon cannons.' } -``` - -##### upgrade from 1.0.4 to 1.0.4 (no changes needed) -```javascript -migrate('1.0.4', '1.0.4', function(err, res) { - if (err) return console.error('Error:', e.message); - console.log('Success:', res); -}); - -// console output -// Success: {} -``` - -##### downgrade from 1.0.8 to 1.0.6 (no internal changes, downgrade ok) -```javascript -migrate('1.0.8', '1.0.6', function(err, res) { - if (err) return console.error('Error:', e.message); - console.log('Success:', res); -}); - -// console output -// Success: {} -``` - -##### downgrade from 1.0.8 to 1.0.3 (incompatible due to internal changes) -```javascript -migrate('1.0.8', '1.0.3', function(err, res) { - if (err) return console.error('Error:', e.message); - console.log('Success:', res); -}); - -// console output -// Error: Downgrade from version 1.0.8 to 1.0.3 not possible. -``` - -[npm_img]: https://img.shields.io/npm/v/app-migrations.svg -[npm_url]: https://npmjs.org/package/app-migrations diff --git a/packages/app-migrations/examples/spaceship.js b/packages/app-migrations/examples/spaceship.js deleted file mode 100644 index b6d2dcd36a5..00000000000 --- a/packages/app-migrations/examples/spaceship.js +++ /dev/null @@ -1,24 +0,0 @@ -/* eslint no-console: 0 */ - -// define your migrations functions, keyed to the version they were introduced at. -var migrations = { - '1.0.4': function(previousVersion, currentVersion, done) { - // introduced new "jetpack" feature which requires changes to the engine. - // ... add code here ... - done(null, 'upgraded engine to support jetpack.'); - }, - '1.0.9': function(previousVersion, currentVersion, done) { - // added photon cannons for more fire power, but needed to deprecate - // laser cannons instead. - // ... add code here ... - done(null, 'removed laser cannons, added photon cannons.'); - } -}; - -var migrate = require('../')(migrations); - -// upgrade from 1.0.5 (we already got jetpacks) to 1.1.4 (need photon cannon) -migrate('1.0.2', '1.1.4', function(err, res) { - if (err) return console.error('Error:', err.message); - console.log('Success:', res); -}); diff --git a/packages/app-migrations/index.js b/packages/app-migrations/index.js deleted file mode 100644 index bb0a047c4f6..00000000000 --- a/packages/app-migrations/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./lib'); diff --git a/packages/app-migrations/lib/index.js b/packages/app-migrations/lib/index.js deleted file mode 100644 index 6b36ff711fc..00000000000 --- a/packages/app-migrations/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -const semver = require('semver'); -const async = require('async'); -const _ = require('lodash'); -const format = require('util').format; -const { log, mongoLogId } = require('@mongodb-js/compass-logging').createLoggerAndTelemetry( - 'COMPASS-MIGRATIONS' -); - -function migrate(migrations) { - return function(previousVersion, currentVersion, done) { - var tasks; - if (semver.lt(previousVersion, currentVersion)) { - // pick migration tasks for upgrade - tasks = _.pickBy(migrations, function(fn, version) { - return semver.gt(version, previousVersion) && - semver.lte(version, currentVersion); - }); - tasks = _.mapValues(tasks, function(fn) { - return fn.bind(null, previousVersion, currentVersion); - }); - log.info(mongoLogId(1001000070), 'Migrations', 'Considering upgrade migration', { - previousVersion, - currentVersion, - tasks: _.keys(tasks) - }); - return async.series(tasks, done); - } - if (semver.gt(previousVersion, currentVersion)) { - // check if the downgrade is compatible with the schema - tasks = _.pickBy(migrations, function(fn, version) { - return semver.gt(version, currentVersion) && - semver.lte(version, previousVersion); - }); - const downgradePossible = _.keys(tasks).length > 0; - log.info(mongoLogId(1001000071), 'Migrations', 'Encountered version downgrade', { - previousVersion, - currentVersion, - downgradePossible - }); - if (downgradePossible) { - // schema incompatible, return error - return done(new Error(format('Downgrade from version %s to %s' - + ' not possible.', previousVersion, currentVersion))); - } - } - done(null, {}); - }; -} - -/** - * - * @api public - */ -module.exports = migrate; diff --git a/packages/app-migrations/package.json b/packages/app-migrations/package.json deleted file mode 100644 index dc3457745cc..00000000000 --- a/packages/app-migrations/package.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "app-migrations", - "description": "Helper for application schema migrations", - "version": "3.2.1", - "scripts": { - "check": "npm run lint && npm run depcheck", - "test": "mocha", - "lint": "eslint \"./{src,lib,test,bin}/**/*.{js,jsx,ts,tsx}\" \"./*.js\" --no-error-on-unmatched-pattern", - "depcheck": "depcheck", - "test-ci": "npm run test" - }, - "author": "Thomas Rueckstiess ", - "homepage": "https://github.com/mongodb-js/compass", - "repository": { - "type": "git", - "url": "https://github.com/mongodb-js/compass.git" - }, - "bugs": { - "url": "https://jira.mongodb.org/projects/COMPASS/issues", - "email": "compass@mongodb.com" - }, - "main": "index.js", - "compass:main": "index.js", - "dependencies": { - "@mongodb-js/compass-logging": "^1.2.1", - "async": "^3.2.2", - "debug": "^4.2.0", - "lodash": "^4.17.21", - "semver": "^7.5.4" - }, - "devDependencies": { - "depcheck": "^1.4.1", - "eslint": "^7.25.0", - "eslint-config-mongodb-js": "^5.0.3", - "mocha": "^10.2.0" - }, - "license": "SSPL" -} diff --git a/packages/app-migrations/test/index.test.js b/packages/app-migrations/test/index.test.js deleted file mode 100644 index 606fee19083..00000000000 --- a/packages/app-migrations/test/index.test.js +++ /dev/null @@ -1,93 +0,0 @@ -var appMigrations = require('../'); -var assert = require('assert'); - -var _ = require('lodash'); -var debug = require('debug')('app-migrations:test'); - - -var migrations = { - '0.9.1': function(previousVersion, currentVersion, cb) { - debug('execute 0.9.1 migration'); - cb(null, '0.9.1'); - }, - '0.9.5': function(previousVersion, currentVersion, cb) { - debug('execute 0.9.5 migration'); - cb(null, '0.9.5'); - }, - '1.0.4': function(previousVersion, currentVersion, cb) { - debug('execute 1.0.4 migration'); - cb(null, '1.0.4'); - }, - '1.1.0': function(previousVersion, currentVersion, cb) { - debug('execute 1.1.0 migration'); - cb(null, '1.1.0'); - }, - '1.2.1': function(previousVersion, currentVersion, cb) { - debug('execute 1.2.1 migration'); - cb(null, '1.2.1'); - }, - '1.2.5': function(previousVersion, currentVersion, cb) { - debug('execute 1.2.5 migration'); - cb(null, '1.2.5'); - } -}; - -describe('Schema Migration', function() { - var migrate; - before(function() { - migrate = appMigrations(migrations); - }); - - it('should have the migrate function', function() { - assert.ok(migrate); - assert.ok(_.isFunction(migrate)); - }); - - it('should not execute tasks if current version <= previous version', function(done) { - migrate('1.0.0', '1.0.0', function(err, res) { - assert.ifError(err); - assert.deepEqual(res, {}); - done(); - }); - }); - - it('should execute migrations between previous and current version', function(done) { - migrate('1.0.0', '1.2.4', function(err, res) { - assert.ifError(err); - assert.deepEqual(_.values(res), ['1.0.4', '1.1.0', '1.2.1']); - done(); - }); - }); - - it('should execute a migration for exactly the current version', function(done) { - migrate('1.0.0', '1.0.4', function(err, res) { - assert.ifError(err); - assert.deepEqual(_.values(res), ['1.0.4']); - done(); - }); - }); - - it('should not execute a migration for exactly the previous version', function(done) { - migrate('1.0.4', '1.0.7', function(err, res) { - assert.ifError(err); - assert.deepEqual(_.values(res), []); - done(); - }); - }); - - it('should not allow incompatible downgrades', function(done) { - migrate('1.5.0', '1.0.0', function(err) { - assert.ok(err); - assert.ok(err.message.match(/Downgrade from version 1.5.0 to 1.0.0 not possible/)); - done(); - }); - }); - - it('should allow compatible downgrades', function(done) { - migrate('1.0.9', '1.0.5', function(err, res) { - assert.ifError(err); - assert.deepEqual(_.values(res), []); - done(); - }); - }); -});