Skip to content

Commit

Permalink
Merge pull request #85 from percolatestudio/feature/modules
Browse files Browse the repository at this point in the history
ES update
  • Loading branch information
StorytellerCZ committed Oct 24, 2022
2 parents 956f1b8 + 3dd7d07 commit 778094e
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 108 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test
on: push

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
meteorRelease:
- '--release 1.9.3'
- '--release 1.12.1'
- '--release 2.1.1'
- '--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 }}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js: "0.10"
node_js: "12"
sudo: false
install:
- "curl https://install.meteor.com | /bin/sh"
Expand Down
7 changes: 7 additions & 0 deletions example/.meteor/.finished-upgraders
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 17 additions & 13 deletions example/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion example/.meteor/release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
METEOR@1.2.0.2
METEOR@2.8.0
146 changes: 80 additions & 66 deletions example/.meteor/versions
Original file line number Diff line number Diff line change
@@ -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.1.0
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
52 changes: 29 additions & 23 deletions migrations_server.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -43,7 +47,7 @@ Migrations = {
collectionName: 'migrations',
},
config: function(opts) {
this.options = _.extend({}, this.options, opts);
this.options = Object.assign({}, this.options, opts);
},
};

Expand All @@ -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({
Expand All @@ -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);
Expand Down Expand Up @@ -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');
}
Expand All @@ -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) {
Expand All @@ -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(
Expand All @@ -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();
Expand Down Expand Up @@ -240,13 +246,13 @@ 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;
updateVersion();
}
} else {
for (var i = startIdx; i > endIdx; i--) {
for (let i = startIdx; i > endIdx; i--) {
migrate('down', i);
currentVersion = self._list[i - 1].version;
updateVersion();
Expand All @@ -257,9 +263,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 });
};
Expand All @@ -281,7 +287,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;
}

Expand Down
2 changes: 2 additions & 0 deletions migrations_tests.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit 778094e

Please sign in to comment.