@oliasoft-open-source/node-json-migrator 2.3.6 → 2.3.7-beta-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.
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setCachedPlannedVersion = exports.getCachedPlannedVersion = void 0;
|
|
6
|
+
exports.setCachedPlannedVersion = exports.setCachedMigratorFunctions = exports.getCachedPlannedVersion = exports.getCachedMigratorFunctions = void 0;
|
|
7
7
|
let cachedPlannedVersion = null;
|
|
8
|
+
let cachedMigratorFunctions = [];
|
|
8
9
|
const getCachedPlannedVersion = () => cachedPlannedVersion;
|
|
9
10
|
exports.getCachedPlannedVersion = getCachedPlannedVersion;
|
|
10
11
|
const setCachedPlannedVersion = version => {
|
|
11
12
|
cachedPlannedVersion = version;
|
|
12
13
|
};
|
|
13
|
-
exports.setCachedPlannedVersion = setCachedPlannedVersion;
|
|
14
|
+
exports.setCachedPlannedVersion = setCachedPlannedVersion;
|
|
15
|
+
const getCachedMigratorFunctions = () => cachedMigratorFunctions;
|
|
16
|
+
exports.getCachedMigratorFunctions = getCachedMigratorFunctions;
|
|
17
|
+
const setCachedMigratorFunctions = scripts => {
|
|
18
|
+
cachedMigratorFunctions = scripts;
|
|
19
|
+
};
|
|
20
|
+
exports.setCachedMigratorFunctions = setCachedMigratorFunctions;
|
package/dist/plan/plan.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.writePlan = exports.sortPlanEntries = exports.readPlan = exports.parsePlan = exports.getPlannedMigrations = exports.getNextSequenceString = exports.generatePlanEntries = exports.formatJSON = void 0;
|
|
6
|
+
exports.writePlan = exports.sortPlanEntries = exports.readPlan = exports.parsePlan = exports.loadMigrationFunctions = exports.getPlannedMigrations = exports.getNextSequenceString = exports.generatePlanEntries = exports.formatJSON = void 0;
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
var _lodash = require("lodash");
|
|
8
9
|
var _fs = require("fs");
|
|
9
10
|
var _moduleFromString = require("module-from-string");
|
|
10
11
|
var _hash = require("../hash/hash");
|
|
@@ -130,6 +131,26 @@ const generatePlanEntries = sortedMigrationEntries => sortedMigrationEntries.map
|
|
|
130
131
|
sequence: m.sequence
|
|
131
132
|
}));
|
|
132
133
|
exports.generatePlanEntries = generatePlanEntries;
|
|
134
|
+
const loadMigrationFunctions = async (sortedMigrationEntries, currentPlanVersion) => {
|
|
135
|
+
const cachedPlannedVersion = (0, _cachedPlannedVersion.getCachedPlannedVersion)();
|
|
136
|
+
const cachedMigratorFunctions = (0, _cachedPlannedVersion.getCachedMigratorFunctions)();
|
|
137
|
+
const cacheValid = cachedPlannedVersion === currentPlanVersion && sortedMigrationEntries.length === cachedMigratorFunctions.length;
|
|
138
|
+
const migrationFunctions = cacheValid ? cachedMigratorFunctions : await Promise.all(sortedMigrationEntries.map(async m => {
|
|
139
|
+
const {
|
|
140
|
+
script
|
|
141
|
+
} = m;
|
|
142
|
+
const migrator = script ? (await (0, _moduleFromString.importFromString)(script))?.default : null;
|
|
143
|
+
return {
|
|
144
|
+
fileHash: m.fileHash,
|
|
145
|
+
migrator
|
|
146
|
+
};
|
|
147
|
+
}));
|
|
148
|
+
if (!cacheValid) {
|
|
149
|
+
(0, _cachedPlannedVersion.setCachedMigratorFunctions)(migrationFunctions);
|
|
150
|
+
}
|
|
151
|
+
return (0, _lodash.merge)(sortedMigrationEntries, migrationFunctions);
|
|
152
|
+
};
|
|
153
|
+
exports.loadMigrationFunctions = loadMigrationFunctions;
|
|
133
154
|
const getPlannedMigrations = async ({
|
|
134
155
|
config
|
|
135
156
|
}) => {
|
|
@@ -173,7 +194,6 @@ const getPlannedMigrations = async ({
|
|
|
173
194
|
const script = filePath ? await _fs.promises.readFile(filePath, {
|
|
174
195
|
encoding: 'utf8'
|
|
175
196
|
}) : null;
|
|
176
|
-
const migrator = script && importModule ? (await (0, _moduleFromString.importFromString)(script))?.default : null;
|
|
177
197
|
const fileHash = script ? (0, _hash.hash)(script) : null;
|
|
178
198
|
|
|
179
199
|
//skipped files
|
|
@@ -195,7 +215,6 @@ const getPlannedMigrations = async ({
|
|
|
195
215
|
filePath,
|
|
196
216
|
isValidFileName,
|
|
197
217
|
script,
|
|
198
|
-
migrator,
|
|
199
218
|
fileHash,
|
|
200
219
|
skippedFileHashes
|
|
201
220
|
};
|
|
@@ -234,9 +253,10 @@ const getPlannedMigrations = async ({
|
|
|
234
253
|
}];
|
|
235
254
|
await (0, _database.insertVersions)(database, pgpHelpers, entity, versionRecord);
|
|
236
255
|
}
|
|
237
|
-
(
|
|
256
|
+
const plannedMigrationsWithFunctions = importModule ? await loadMigrationFunctions(plannedMigrationsWithFileEntries, nextVersion, importModule) : plannedMigrationsWithFileEntries;
|
|
257
|
+
(0, _cachedPlannedVersion.setCachedPlannedVersion)(nextVersion); //Must set _after_ loading migration functions
|
|
238
258
|
return {
|
|
239
|
-
plannedMigrations:
|
|
259
|
+
plannedMigrations: plannedMigrationsWithFunctions,
|
|
240
260
|
nextVersion
|
|
241
261
|
};
|
|
242
262
|
};
|
package/package.json
CHANGED