masterrecord 0.2.14 → 0.2.17
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/Migrations/cli.js +5 -3
- package/Migrations/migrations.js +12 -9
- package/package.json +2 -2
package/Migrations/cli.js
CHANGED
|
@@ -569,21 +569,23 @@ program.option('-V', 'output the version');
|
|
|
569
569
|
var executedLocation = process.cwd();
|
|
570
570
|
try{
|
|
571
571
|
// Find all context snapshots and run update per snapshot (avoids unrelated framework contexts)
|
|
572
|
-
var snapshotFiles = globSearch.sync(
|
|
572
|
+
var snapshotFiles = globSearch.sync('**/*_contextSnapShot.json', executedLocation);
|
|
573
573
|
if(!(snapshotFiles && snapshotFiles.length)){
|
|
574
574
|
console.log('No context snapshots found. Run enable-migrations for each context first.');
|
|
575
575
|
return;
|
|
576
576
|
}
|
|
577
577
|
// Group snapshots by context name (case-insensitive) and pick best per group
|
|
578
578
|
var groups = {};
|
|
579
|
-
for(const
|
|
579
|
+
for(const snapRel of snapshotFiles){
|
|
580
|
+
const snapFile = path.resolve(executedLocation, snapRel);
|
|
580
581
|
let cs;
|
|
581
582
|
try{ cs = require(snapFile); }catch(_){ continue; }
|
|
582
583
|
const nameFromPath = path.basename(snapFile).replace(/_contextSnapShot\.json$/i, '').toLowerCase();
|
|
583
584
|
const ctxName = (cs && cs.contextLocation)
|
|
584
585
|
? path.basename(cs.contextLocation).replace(/\.js$/i, '').toLowerCase()
|
|
585
586
|
: nameFromPath;
|
|
586
|
-
const
|
|
587
|
+
const migRel = globSearch.sync('**/*_migration.js', cs.migrationFolder) || [];
|
|
588
|
+
const migs = migRel.map(f => path.resolve(cs.migrationFolder, f));
|
|
587
589
|
if(!groups[ctxName]) groups[ctxName] = [];
|
|
588
590
|
groups[ctxName].push({ snapFile, cs, ctxName, migs });
|
|
589
591
|
}
|
package/Migrations/migrations.js
CHANGED
|
@@ -5,6 +5,7 @@ var fs = require('fs');
|
|
|
5
5
|
var diff = require("deep-object-diff");
|
|
6
6
|
var MigrationTemplate = require("./migrationTemplate");
|
|
7
7
|
var globSearch = require("glob");
|
|
8
|
+
var path = require('path');
|
|
8
9
|
|
|
9
10
|
// https://blog.tekspace.io/code-first-multiple-db-context-migration/
|
|
10
11
|
|
|
@@ -203,28 +204,30 @@ class Migrations{
|
|
|
203
204
|
}
|
|
204
205
|
|
|
205
206
|
createSnapShot(snap){
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
// Place migrations alongside the Context file by default:
|
|
208
|
+
// <ContextDir>/db/migrations/<context>_contextSnapShot.json
|
|
209
|
+
const contextDir = path.dirname(snap.file);
|
|
210
|
+
const dbFolder = path.join(contextDir, 'db');
|
|
208
211
|
if (!fs.existsSync(dbFolder)){
|
|
209
|
-
fs.mkdirSync(dbFolder);
|
|
212
|
+
fs.mkdirSync(dbFolder, { recursive: true });
|
|
210
213
|
}
|
|
211
214
|
|
|
212
|
-
|
|
215
|
+
const migrationsDirectory = path.join(dbFolder, 'migrations');
|
|
213
216
|
if (!fs.existsSync(migrationsDirectory)){
|
|
214
|
-
fs.mkdirSync(migrationsDirectory);
|
|
217
|
+
fs.mkdirSync(migrationsDirectory, { recursive: true });
|
|
215
218
|
}
|
|
216
219
|
|
|
220
|
+
const snapshotPath = path.join(migrationsDirectory, `${snap.contextFileName}_contextSnapShot.json`);
|
|
217
221
|
var content = {
|
|
218
222
|
contextLocation: snap.file,
|
|
219
|
-
migrationFolder:
|
|
220
|
-
snapShotLocation:
|
|
223
|
+
migrationFolder: migrationsDirectory,
|
|
224
|
+
snapShotLocation: snapshotPath,
|
|
221
225
|
schema : snap.contextEntities
|
|
222
226
|
};
|
|
223
227
|
|
|
224
228
|
const jsonContent = JSON.stringify(content, null, 2);
|
|
225
229
|
try{
|
|
226
|
-
|
|
227
|
-
fs.writeFileSync(`${migrationsDirectory}/${snap.contextFileName}_contextSnapShot.json`, jsonContent);
|
|
230
|
+
fs.writeFileSync(snapshotPath, jsonContent);
|
|
228
231
|
}catch (e){
|
|
229
232
|
console.log("Cannot write file ", e);
|
|
230
233
|
}
|
package/package.json
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
"glob" : "^11.0.3",
|
|
6
6
|
"deep-object-diff" : "^1.1.9",
|
|
7
7
|
"pg" : "^8.16.3",
|
|
8
|
-
"sync-mysql2" : "^1.0.
|
|
8
|
+
"sync-mysql2" : "^1.0.7",
|
|
9
9
|
"app-root-path": "^3.1.0",
|
|
10
10
|
"better-sqlite3": "^12.4.1"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.2.
|
|
12
|
+
"version": "0.2.17",
|
|
13
13
|
"description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
|
|
14
14
|
"homepage": "https://github.com/Tailor/MasterRecord#readme",
|
|
15
15
|
"repository": {
|