@villedemontreal/mongo 7.0.0-beta → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/scripts/index.d.ts +6 -0
- package/dist/scripts/index.js +16 -0
- package/dist/scripts/index.js.map +1 -0
- package/dist/scripts/lint.d.ts +6 -0
- package/dist/scripts/lint.js +18 -0
- package/dist/scripts/lint.js.map +1 -0
- package/dist/scripts/lintFix.d.ts +6 -0
- package/dist/scripts/lintFix.js +21 -0
- package/dist/scripts/lintFix.js.map +1 -0
- package/dist/scripts/showCoverage.d.ts +13 -0
- package/dist/scripts/showCoverage.js +40 -0
- package/dist/scripts/showCoverage.js.map +1 -0
- package/dist/scripts/test.d.ts +13 -0
- package/dist/scripts/test.js +29 -0
- package/dist/scripts/test.js.map +1 -0
- package/dist/scripts/testUnits.d.ts +15 -0
- package/dist/scripts/testUnits.js +95 -0
- package/dist/scripts/testUnits.js.map +1 -0
- package/dist/scripts/watch.d.ts +14 -0
- package/dist/scripts/watch.js +96 -0
- package/dist/scripts/watch.js.map +1 -0
- package/dist/src/config/configs.d.ts +3 -0
- package/dist/src/config/configs.js +6 -0
- package/dist/src/config/configs.js.map +1 -1
- package/dist/src/mongoClient.js +63 -58
- package/dist/src/mongoClient.js.map +1 -1
- package/dist/src/mongoUpdater.js +9 -9
- package/dist/src/mongoUpdater.js.map +1 -1
- package/dist/src/mongoUpdater.test.js +9 -9
- package/dist/src/mongoUpdater.test.js.map +1 -1
- package/dist/src/mongoUtils.js +4 -1
- package/dist/src/mongoUtils.js.map +1 -1
- package/dist/src/mongoUtils.test.js +1 -0
- package/dist/src/mongoUtils.test.js.map +1 -1
- package/dist/src/plugins/pagination/index.test.js +1 -1
- package/dist/src/plugins/pagination/index.test.js.map +1 -1
- package/dist/tests/testingMongoUpdates/1.0.1.js +1 -1
- package/dist/tests/testingMongoUpdates/1.0.1.js.map +1 -1
- package/package.json +18 -16
- package/src/config/configs.ts +9 -0
- package/src/mongoClient.ts +80 -69
- package/src/mongoUpdater.test.ts +9 -9
- package/src/mongoUpdater.ts +9 -10
- package/src/plugins/pagination/index.test.ts +1 -1
package/src/mongoUpdater.test.ts
CHANGED
|
@@ -50,14 +50,14 @@ describe('Mongo Updater', () => {
|
|
|
50
50
|
await mongoDb.dropDatabase();
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
describe('getSchemaVersion',
|
|
53
|
+
describe('getSchemaVersion', () => {
|
|
54
54
|
it('should contain schema version 0.0.0', async () => {
|
|
55
55
|
const version: string = await mongoUpdater.getAppSchemaVersion();
|
|
56
56
|
assert.strictEqual(version, '0.0.0');
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
describe('checkInstall',
|
|
60
|
+
describe('checkInstall', () => {
|
|
61
61
|
let installAppSchemaCollectionSpy: sinon.SinonSpy;
|
|
62
62
|
|
|
63
63
|
beforeEach(async () => {
|
|
@@ -108,14 +108,14 @@ describe('Mongo Updater', () => {
|
|
|
108
108
|
});
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
-
describe('getSchemaVersion',
|
|
111
|
+
describe('getSchemaVersion', () => {
|
|
112
112
|
it('should contain schema version 0.0.0', async () => {
|
|
113
113
|
const version: string = await mongoUpdater.getAppSchemaVersion();
|
|
114
114
|
assert.strictEqual(version, '0.0.0');
|
|
115
115
|
});
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
describe('lock',
|
|
118
|
+
describe('lock', () => {
|
|
119
119
|
it('lock should be equal to false', async () => {
|
|
120
120
|
const schema: MongoDb.Collection = mongoDb.collection(
|
|
121
121
|
testconfig.updater.appSchemaCollectionName
|
|
@@ -143,7 +143,7 @@ describe('Mongo Updater', () => {
|
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
145
|
|
|
146
|
-
describe('unlock',
|
|
146
|
+
describe('unlock', () => {
|
|
147
147
|
it('lock should be equal to true', async () => {
|
|
148
148
|
const schema: MongoDb.Collection = mongoDb.collection(
|
|
149
149
|
testconfig.updater.appSchemaCollectionName
|
|
@@ -177,7 +177,7 @@ describe('Mongo Updater', () => {
|
|
|
177
177
|
});
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
-
describe('updateSchemaVersion',
|
|
180
|
+
describe('updateSchemaVersion', () => {
|
|
181
181
|
it('should contain schema version 0.0.0', async () => {
|
|
182
182
|
const version: string = await mongoUpdater.getAppSchemaVersion();
|
|
183
183
|
assert.strictEqual(version, '0.0.0');
|
|
@@ -198,7 +198,7 @@ describe('Mongo Updater', () => {
|
|
|
198
198
|
});
|
|
199
199
|
});
|
|
200
200
|
|
|
201
|
-
describe('checkUpdate',
|
|
201
|
+
describe('checkUpdate', () => {
|
|
202
202
|
let lockSpy: sinon.SinonSpy;
|
|
203
203
|
let applyUpdateSchemasSpy: sinon.SinonSpy;
|
|
204
204
|
let updateSchemaVersionSpy: sinon.SinonSpy;
|
|
@@ -262,7 +262,7 @@ describe('Mongo Updater', () => {
|
|
|
262
262
|
});
|
|
263
263
|
});
|
|
264
264
|
|
|
265
|
-
describe('getUpdateFiles',
|
|
265
|
+
describe('getUpdateFiles', () => {
|
|
266
266
|
it('should not contain files for version between 0.0.0 and 0.0.0', async () => {
|
|
267
267
|
const files: string[] = await mongoUpdater.getAppSchemaUpdateFiles('0.0.0', '0.0.0');
|
|
268
268
|
assert.strictEqual(files.length, 0);
|
|
@@ -281,7 +281,7 @@ describe('Mongo Updater', () => {
|
|
|
281
281
|
});
|
|
282
282
|
});
|
|
283
283
|
|
|
284
|
-
describe('applyUpdateSchemas',
|
|
284
|
+
describe('applyUpdateSchemas', () => {
|
|
285
285
|
let getUpdateFilesSpy: sinon.SinonSpy;
|
|
286
286
|
beforeEach(async () => {
|
|
287
287
|
getUpdateFilesSpy = sinon.spy(mongoUpdater, 'getAppSchemaUpdateFiles');
|
package/src/mongoUpdater.ts
CHANGED
|
@@ -235,7 +235,7 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
public async getAppSchemaCollection(): Promise<MongoDb.Collection> {
|
|
238
|
-
return
|
|
238
|
+
return this.mongoDb.collection(this.appSchemaCollectionName);
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
public async getAppSchemaVersion(): Promise<string> {
|
|
@@ -367,14 +367,15 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
367
367
|
logger.info('Checking for db app schema updates:');
|
|
368
368
|
|
|
369
369
|
let lockAcquired = false;
|
|
370
|
+
let currentAppSchemaVersion: string | undefined;
|
|
370
371
|
const targetVersion: string = this.findMongoAppSchemaTargetVersion();
|
|
371
372
|
try {
|
|
372
|
-
while (
|
|
373
|
+
while (!lockAcquired) {
|
|
373
374
|
// ==========================================
|
|
374
375
|
// Checks if the appSchema version has to be
|
|
375
376
|
// updated.
|
|
376
377
|
// ==========================================
|
|
377
|
-
|
|
378
|
+
currentAppSchemaVersion = await this.getAppSchemaVersion();
|
|
378
379
|
if (semver.gte(currentAppSchemaVersion, targetVersion)) {
|
|
379
380
|
// tslint:disable-next-line: prefer-template
|
|
380
381
|
logger.info(
|
|
@@ -383,13 +384,6 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
383
384
|
return;
|
|
384
385
|
}
|
|
385
386
|
|
|
386
|
-
if (lockAcquired) {
|
|
387
|
-
logger.info(` > Applying some required updates...`);
|
|
388
|
-
await this.applyAppSchemaUpdates(currentAppSchemaVersion, targetVersion);
|
|
389
|
-
await this.updateAppSchemaVersion(currentAppSchemaVersion, targetVersion);
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
387
|
// ==========================================
|
|
394
388
|
// Tries to get the lock. Will do this as long
|
|
395
389
|
// as the lock can't be acquired (ie : it is
|
|
@@ -408,6 +402,11 @@ export class MongoUpdater implements IMongoUpdater {
|
|
|
408
402
|
logger.info(` > Lock acquired.`);
|
|
409
403
|
}
|
|
410
404
|
}
|
|
405
|
+
if (lockAcquired && currentAppSchemaVersion) {
|
|
406
|
+
logger.info(` > Applying some required updates...`);
|
|
407
|
+
await this.applyAppSchemaUpdates(currentAppSchemaVersion, targetVersion);
|
|
408
|
+
await this.updateAppSchemaVersion(currentAppSchemaVersion, targetVersion);
|
|
409
|
+
}
|
|
411
410
|
} finally {
|
|
412
411
|
if (lockAcquired) {
|
|
413
412
|
await this.unlockAppSchemaDocument();
|
|
@@ -46,7 +46,7 @@ describe('plugin pagination', () => {
|
|
|
46
46
|
return authorModel.create({ name: 'Arthur Conan Doyle' }).then((author) => {
|
|
47
47
|
for (let i = 1; i <= 100; i++) {
|
|
48
48
|
book = new bookModel({
|
|
49
|
-
title:
|
|
49
|
+
title: `Book #${i}`,
|
|
50
50
|
date: new Date(date.getTime() + i),
|
|
51
51
|
author: author._id,
|
|
52
52
|
});
|