@oliasoft-open-source/node-json-migrator 2.3.6 → 2.3.7-beta-2
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,27 @@ const generatePlanEntries = sortedMigrationEntries => sortedMigrationEntries.map
|
|
|
130
131
|
sequence: m.sequence
|
|
131
132
|
}));
|
|
132
133
|
exports.generatePlanEntries = generatePlanEntries;
|
|
134
|
+
const loadMigrationFunctions = async (sortedMigrationEntries, nextVersion, importModule = true) => {
|
|
135
|
+
const cachedPlannedVersion = (0, _cachedPlannedVersion.getCachedPlannedVersion)();
|
|
136
|
+
const cachedMigratorFunctions = (0, _cachedPlannedVersion.getCachedMigratorFunctions)();
|
|
137
|
+
const cacheValid = cachedPlannedVersion === nextVersion && 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 && importModule ? (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
|
+
(0, _cachedPlannedVersion.setCachedPlannedVersion)(nextVersion);
|
|
151
|
+
}
|
|
152
|
+
return (0, _lodash.merge)(sortedMigrationEntries, migrationFunctions);
|
|
153
|
+
};
|
|
154
|
+
exports.loadMigrationFunctions = loadMigrationFunctions;
|
|
133
155
|
const getPlannedMigrations = async ({
|
|
134
156
|
config
|
|
135
157
|
}) => {
|
|
@@ -173,7 +195,6 @@ const getPlannedMigrations = async ({
|
|
|
173
195
|
const script = filePath ? await _fs.promises.readFile(filePath, {
|
|
174
196
|
encoding: 'utf8'
|
|
175
197
|
}) : null;
|
|
176
|
-
const migrator = script && importModule ? (await (0, _moduleFromString.importFromString)(script))?.default : null;
|
|
177
198
|
const fileHash = script ? (0, _hash.hash)(script) : null;
|
|
178
199
|
|
|
179
200
|
//skipped files
|
|
@@ -195,7 +216,6 @@ const getPlannedMigrations = async ({
|
|
|
195
216
|
filePath,
|
|
196
217
|
isValidFileName,
|
|
197
218
|
script,
|
|
198
|
-
migrator,
|
|
199
219
|
fileHash,
|
|
200
220
|
skippedFileHashes
|
|
201
221
|
};
|
|
@@ -234,9 +254,9 @@ const getPlannedMigrations = async ({
|
|
|
234
254
|
}];
|
|
235
255
|
await (0, _database.insertVersions)(database, pgpHelpers, entity, versionRecord);
|
|
236
256
|
}
|
|
237
|
-
(
|
|
257
|
+
const plannedMigrationsWithFunctions = await loadMigrationFunctions(plannedMigrationsWithFileEntries, nextVersion, importModule);
|
|
238
258
|
return {
|
|
239
|
-
plannedMigrations:
|
|
259
|
+
plannedMigrations: plannedMigrationsWithFunctions,
|
|
240
260
|
nextVersion
|
|
241
261
|
};
|
|
242
262
|
};
|
package/package.json
CHANGED