From 5242d194a5f2f79a5672b090be08cd38d3006192 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Mon, 24 Oct 2022 11:10:28 +0200 Subject: [PATCH 1/6] Start ES migration --- migrations_server.js | 52 ++++++++++++++++++++++++-------------------- migrations_tests.js | 2 ++ package.js | 6 ++--- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/migrations_server.js b/migrations_server.js index a6c83db..3eccf04 100644 --- a/migrations_server.js +++ b/migrations_server.js @@ -1,3 +1,7 @@ +import { Meteor } from 'meteor/meteor'; +import { check, Match } from 'meteor/check'; +import { Log } from 'meteor/logging'; + /* Adds migration capabilities. Migrations are defined like: @@ -23,14 +27,14 @@ Note: Migrations will lock ensuring only 1 app can be migrating at once. If a migration crashes, the control record in the migrations collection will remain locked and at the version it was at previously, however the db could - be in an inconsistant state. + be in an inconsistent state. */ // since we'll be at version 0 by default, we should have a migration set for // it. -var DefaultMigration = { version: 0, up: function() {} }; +const DefaultMigration = { version: 0, up: function() {} }; -Migrations = { +export const Migrations = { _list: [DefaultMigration], options: { // false disables logging @@ -43,7 +47,7 @@ Migrations = { collectionName: 'migrations', }, config: function(opts) { - this.options = _.extend({}, this.options, opts); + this.options = Object.assign({}, this.options, opts); }, }; @@ -68,7 +72,7 @@ function createLogger(prefix) { check(level, Match.OneOf('info', 'error', 'warn', 'debug')); check(message, String); - var logger = Migrations.options && Migrations.options.logger; + const logger = Migrations.options && Migrations.options.logger; if (logger && _.isFunction(logger)) { logger({ @@ -82,10 +86,10 @@ function createLogger(prefix) { }; } -var log; +let log; Meteor.startup(function() { - var options = Migrations.options; + const options = Migrations.options; // collection holding the control record Migrations._collection = new Mongo.Collection(options.collectionName); @@ -128,18 +132,20 @@ Migrations.add = function(migration) { // e.g 'latest', 'latest,exit', 2 // use 'XX,rerun' to re-run the migration at that version Migrations.migrateTo = function(command) { - if (_.isUndefined(command) || command === '' || this._list.length === 0) + if (typeof command === 'undefined' || command === '' || this._list.length === 0) throw new Error('Cannot migrate using invalid command: ' + command); + let version; + let subcommand; if (typeof command === 'number') { - var version = command; + version = command; } else { - var version = command.split(',')[0]; //.trim(); - var subcommand = command.split(',')[1]; //.trim(); + version = command.split(',')[0]; //.trim(); + subcommand = command.split(',')[1]; //.trim(); } if (version === 'latest') { - this._migrateTo(_.last(this._list).version); + this._migrateTo(this._list[this._list.length -1].version); } else { this._migrateTo(parseInt(version), subcommand === 'rerun'); } @@ -155,9 +161,9 @@ Migrations.getVersion = function() { // migrates to the specific version passed in Migrations._migrateTo = function(version, rerun) { - var self = this; - var control = this._getControl(); // Side effect: upserts control document. - var currentVersion = control.version; + const self = this; + const control = this._getControl(); // Side effect: upserts control document. + let currentVersion = control.version; //Avoid unneeded locking, check if migration actually is going to run if (!rerun && currentVersion === version) { @@ -180,8 +186,8 @@ Migrations._migrateTo = function(version, rerun) { return; } - var startIdx = this._findIndexByVersion(currentVersion); - var endIdx = this._findIndexByVersion(version); + const startIdx = this._findIndexByVersion(currentVersion); + const endIdx = this._findIndexByVersion(version); // log.info('startIdx:' + startIdx + ' endIdx:' + endIdx); log.info( @@ -193,7 +199,7 @@ Migrations._migrateTo = function(version, rerun) { // run the actual migration function migrate(direction, idx) { - var migration = self._list[idx]; + const migration = self._list[idx]; if (typeof migration[direction] !== 'function') { unlock(); @@ -236,12 +242,12 @@ Migrations._migrateTo = function(version, rerun) { } if (currentVersion < version) { - for (var i = startIdx; i < endIdx; i++) { + for (let i = startIdx; i < endIdx; i++) { migrate('up', i + 1); currentVersion = self._list[i + 1].version; } } else { - for (var i = startIdx; i > endIdx; i--) { + for (let i = startIdx; i > endIdx; i--) { migrate('down', i); currentVersion = self._list[i - 1].version; } @@ -251,9 +257,9 @@ Migrations._migrateTo = function(version, rerun) { log.info('Finished migrating.'); }; -// gets the current control record, optionally creating it if non-existant +// gets the current control record, optionally creating it if non-existent Migrations._getControl = function() { - var control = this._collection.findOne({ _id: 'control' }); + const control = this._collection.findOne({ _id: 'control' }); return control || this._setControl({ version: 0, locked: false }); }; @@ -275,7 +281,7 @@ Migrations._setControl = function(control) { // returns the migration index in _list or throws if not found Migrations._findIndexByVersion = function(version) { - for (var i = 0; i < this._list.length; i++) { + for (let i = 0; i < this._list.length; i++) { if (this._list[i].version === version) return i; } diff --git a/migrations_tests.js b/migrations_tests.js index de8b7fb..bf286b2 100644 --- a/migrations_tests.js +++ b/migrations_tests.js @@ -1,3 +1,5 @@ +import { Migrations } from './migrations_server' + Tinytest.add('Migrates up once and only once.', function(test) { var run = []; //keeps track of migrations in here Migrations._reset(); diff --git a/package.js b/package.js index f85ae9a..0afaa37 100644 --- a/package.js +++ b/package.js @@ -1,15 +1,15 @@ Package.describe({ summary: 'Define and run db migrations.', - version: '1.0.3', + version: '1.1.0', name: 'percolate:migrations', git: 'https://github.com/percolatestudio/meteor-migrations.git', }); Package.onUse(function(api) { - api.versionsFrom('METEOR@1.5'); + api.versionsFrom('METEOR@1.9'); api.use('ecmascript'); api.use(['underscore', 'check', 'mongo', 'logging'], 'server'); - api.addFiles(['migrations_server.js'], 'server'); + api.mainModule(['migrations_server.js'], 'server'); api.export('Migrations', 'server'); }); From 9c4970ade3257449b6fb837b0177adc75b2e3fb2 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Mon, 24 Oct 2022 11:14:03 +0200 Subject: [PATCH 2/6] Update example Meteor version --- example/.meteor/.finished-upgraders | 7 ++ example/.meteor/packages | 30 +++--- example/.meteor/release | 2 +- example/.meteor/versions | 146 +++++++++++++++------------- 4 files changed, 105 insertions(+), 80 deletions(-) diff --git a/example/.meteor/.finished-upgraders b/example/.meteor/.finished-upgraders index 61ee313..c07b6ff 100644 --- a/example/.meteor/.finished-upgraders +++ b/example/.meteor/.finished-upgraders @@ -10,3 +10,10 @@ notices-for-facebook-graph-api-2 1.2.0-meteor-platform-split 1.2.0-cordova-changes 1.2.0-breaking-changes +1.3.0-split-minifiers-package +1.4.0-remove-old-dev-bundle-link +1.4.1-add-shell-server-package +1.4.3-split-account-service-packages +1.5-add-dynamic-import-package +1.7-split-underscore-from-meteor-base +1.8.3-split-jquery-from-blaze diff --git a/example/.meteor/packages b/example/.meteor/packages index 6cb8cb4..750600c 100644 --- a/example/.meteor/packages +++ b/example/.meteor/packages @@ -3,20 +3,24 @@ # 'meteor add' and 'meteor remove' will edit this file for you, # but you can also edit it by hand. -autopublish -insecure +autopublish@1.0.7 +insecure@1.0.7 percolate:migrations -standard-minifiers -meteor-base -mobile-experience -mongo +meteor-base@1.5.1 +mobile-experience@1.1.0 +mongo@1.16.0 blaze-html-templates -session +session@1.2.0 jquery -tracker -logging -reload -random -ejson +tracker@1.2.0 +logging@1.3.1 +reload@1.3.1 +random@1.2.0 +ejson@1.1.2 spacebars -check +check@1.3.1 +standard-minifier-css +standard-minifier-js +shell-server +dynamic-import +underscore diff --git a/example/.meteor/release b/example/.meteor/release index 5684262..1d2a6d0 100644 --- a/example/.meteor/release +++ b/example/.meteor/release @@ -1 +1 @@ -METEOR@1.2.0.2 +METEOR@2.8.0 diff --git a/example/.meteor/versions b/example/.meteor/versions index 046be59..42471f9 100644 --- a/example/.meteor/versions +++ b/example/.meteor/versions @@ -1,66 +1,80 @@ -autopublish@1.0.4 -autoupdate@1.2.3 -babel-compiler@5.8.24_1 -babel-runtime@0.1.4 -base64@1.0.4 -binary-heap@1.0.4 -blaze@2.1.3 -blaze-html-templates@1.0.1 -blaze-tools@1.0.4 -boilerplate-generator@1.0.4 -caching-compiler@1.0.0 -caching-html-compiler@1.0.2 -callback-hook@1.0.4 -check@1.0.6 -ddp@1.2.2 -ddp-client@1.2.1 -ddp-common@1.2.1 -ddp-server@1.2.1 -deps@1.0.9 -diff-sequence@1.0.1 -ecmascript@0.1.5 -ecmascript-collections@0.1.6 -ejson@1.0.7 -fastclick@1.0.7 -geojson-utils@1.0.4 -hot-code-push@1.0.0 -html-tools@1.0.5 -htmljs@1.0.5 -http@1.1.1 -id-map@1.0.4 -insecure@1.0.4 -jquery@1.11.4 -launch-screen@1.0.4 -livedata@1.0.15 -logging@1.0.8 -meteor@1.1.9 -meteor-base@1.0.1 -minifiers@1.1.7 -minimongo@1.0.10 -mobile-experience@1.0.1 -mobile-status-bar@1.0.6 -mongo@1.1.2 -mongo-id@1.0.1 -npm-mongo@1.4.39_1 -observe-sequence@1.0.7 -ordered-dict@1.0.4 -percolate:migrations@0.9.6 -promise@0.5.0 -random@1.0.4 -reactive-dict@1.1.2 -reactive-var@1.0.6 -reload@1.1.4 -retry@1.0.4 -routepolicy@1.0.6 -session@1.1.1 -spacebars@1.0.7 -spacebars-compiler@1.0.7 -standard-minifiers@1.0.1 -templating@1.1.4 -templating-tools@1.0.0 -tracker@1.0.9 -ui@1.0.8 -underscore@1.0.4 -url@1.0.5 -webapp@1.2.2 -webapp-hashing@1.0.5 +allow-deny@1.1.1 +autopublish@1.0.7 +autoupdate@1.8.0 +babel-compiler@7.9.2 +babel-runtime@1.5.1 +base64@1.0.12 +binary-heap@1.0.11 +blaze@2.5.0 +blaze-html-templates@1.2.1 +blaze-tools@1.1.3 +boilerplate-generator@1.7.1 +caching-compiler@1.2.2 +caching-html-compiler@1.2.0 +callback-hook@1.4.0 +check@1.3.1 +ddp@1.4.0 +ddp-client@2.6.0 +ddp-common@1.4.0 +ddp-server@2.6.0 +diff-sequence@1.1.1 +dynamic-import@0.7.2 +ecmascript@0.16.2 +ecmascript-runtime@0.8.0 +ecmascript-runtime-client@0.12.1 +ecmascript-runtime-server@0.11.0 +ejson@1.1.2 +es5-shim@4.8.0 +fetch@0.1.1 +geojson-utils@1.0.10 +hot-code-push@1.0.4 +html-tools@1.1.3 +htmljs@1.1.1 +id-map@1.1.1 +insecure@1.0.7 +inter-process-messaging@0.1.1 +jquery@1.11.11 +launch-screen@1.3.0 +logging@1.3.1 +meteor@1.10.1 +meteor-base@1.5.1 +minifier-css@1.6.1 +minifier-js@2.7.5 +minimongo@1.9.0 +mobile-experience@1.1.0 +mobile-status-bar@1.1.0 +modern-browsers@0.1.8 +modules@0.19.0 +modules-runtime@0.13.0 +mongo@1.16.0 +mongo-decimal@0.1.3 +mongo-dev-server@1.1.0 +mongo-id@1.0.8 +npm-mongo@4.9.0 +observe-sequence@1.0.20 +ordered-dict@1.1.0 +percolate:migrations@1.0.3 +promise@0.12.0 +random@1.2.0 +react-fast-refresh@0.2.3 +reactive-dict@1.3.0 +reactive-var@1.0.11 +reload@1.3.1 +retry@1.1.0 +routepolicy@1.1.1 +session@1.2.0 +shell-server@0.5.0 +socket-stream-client@0.5.0 +spacebars@1.3.0 +spacebars-compiler@1.2.1 +standard-minifier-css@1.8.2 +standard-minifier-js@2.8.1 +templating@1.4.1 +templating-compiler@1.4.1 +templating-runtime@1.5.0 +templating-tools@1.2.0 +tracker@1.2.0 +ui@1.0.13 +underscore@1.0.10 +webapp@1.13.1 +webapp-hashing@1.1.0 From 60ae0428acb5f6323cc4d725fea694f9dce9a70e Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Mon, 24 Oct 2022 11:15:01 +0200 Subject: [PATCH 3/6] Fix issue in package.js --- example/.meteor/versions | 2 +- package.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/.meteor/versions b/example/.meteor/versions index 42471f9..ee2e7cd 100644 --- a/example/.meteor/versions +++ b/example/.meteor/versions @@ -53,7 +53,7 @@ mongo-id@1.0.8 npm-mongo@4.9.0 observe-sequence@1.0.20 ordered-dict@1.1.0 -percolate:migrations@1.0.3 +percolate:migrations@1.1.0 promise@0.12.0 random@1.2.0 react-fast-refresh@0.2.3 diff --git a/package.js b/package.js index 0afaa37..35ee384 100644 --- a/package.js +++ b/package.js @@ -9,7 +9,7 @@ Package.onUse(function(api) { api.versionsFrom('METEOR@1.9'); api.use('ecmascript'); api.use(['underscore', 'check', 'mongo', 'logging'], 'server'); - api.mainModule(['migrations_server.js'], 'server'); + api.mainModule('migrations_server.js', 'server'); api.export('Migrations', 'server'); }); From b900037d919b4bfc573e688a9a5be6d361413596 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Mon, 24 Oct 2022 11:22:33 +0200 Subject: [PATCH 4/6] Try adding GitHub tests --- .github/workflows/test.yml | 33 +++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ac6532e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Test +on: push + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + meteorRelease: + - '--release 1.9' + - '--release 1.12.1' + - '--release 2.1.1' + - '--release 2.2.3' + - '--release 2.3.5' + - '--release 2.8.0' + # Latest version + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Node.js + uses: actions/setup-node@v1 + with: + node-version: '14.x' + + - name: Install Dependencies + run: | + curl https://install.meteor.com | /bin/sh + npm i -g @zodern/mtest + - name: Run Tests + run: | + # Retry tests since some of them are flaky + mtest --package ./ --once ${{ matrix.meteorRelease }} || mtest --package ./ --once ${{ matrix.meteorRelease }} diff --git a/package.json b/package.json index 35ecc77..59968b1 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "homepage": "https://atmospherejs.com/percolate/migrations", "dependencies": { - "spacejam": "^1.2.0" + "spacejam": "1.2.2" }, "keywords": [ "meteor", From 887710cc4aa0a8212ab2269e2ada589be73931f7 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Mon, 24 Oct 2022 11:32:56 +0200 Subject: [PATCH 5/6] Remove one testing version --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac6532e..55da3d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,10 +7,9 @@ jobs: strategy: matrix: meteorRelease: - - '--release 1.9' + - '--release 1.9.3' - '--release 1.12.1' - '--release 2.1.1' - - '--release 2.2.3' - '--release 2.3.5' - '--release 2.8.0' # Latest version From 3dd7d071594e4a3d15b46edfe3bd8d94b5a14227 Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Mon, 24 Oct 2022 11:35:56 +0200 Subject: [PATCH 6/6] Update Travis node version I don't think that is going to fix Travis tests and we have now GitHub tests, so it is more of a vanity thing. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 57ad0d4..d5a3072 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js -node_js: "0.10" +node_js: "12" sudo: false install: - "curl https://install.meteor.com | /bin/sh"