@oliasoft-open-source/node-json-migrator 2.3.7-beta-1 → 2.3.7-beta-3

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.
Files changed (2) hide show
  1. package/dist/plan/plan.js +11 -5
  2. package/package.json +1 -1
package/dist/plan/plan.js CHANGED
@@ -131,15 +131,21 @@ const generatePlanEntries = sortedMigrationEntries => sortedMigrationEntries.map
131
131
  sequence: m.sequence
132
132
  }));
133
133
  exports.generatePlanEntries = generatePlanEntries;
134
- const loadMigrationFunctions = async (sortedMigrationEntries, currentPlanVersion) => {
134
+ const loadMigrationFunctions = async (sortedMigrationEntries, nextVersion, importModule = true) => {
135
135
  const cachedPlannedVersion = (0, _cachedPlannedVersion.getCachedPlannedVersion)();
136
136
  const cachedMigratorFunctions = (0, _cachedPlannedVersion.getCachedMigratorFunctions)();
137
- const cacheValid = cachedPlannedVersion === currentPlanVersion && sortedMigrationEntries.length === cachedMigratorFunctions.length;
137
+ const cacheValid = cachedPlannedVersion === nextVersion && sortedMigrationEntries.length === cachedMigratorFunctions.length;
138
+ /*
139
+ OW-15584 the module-from-string package seems to have a memory leak bug
140
+ where calling importFromString multiple times consumes memory that
141
+ doesn't get released or garbage collected. We cache the imported strings
142
+ as a workaround (until plan.json version changes)
143
+ */
138
144
  const migrationFunctions = cacheValid ? cachedMigratorFunctions : await Promise.all(sortedMigrationEntries.map(async m => {
139
145
  const {
140
146
  script
141
147
  } = m;
142
- const migrator = script ? (await (0, _moduleFromString.importFromString)(script))?.default : null;
148
+ const migrator = script && importModule ? (await (0, _moduleFromString.importFromString)(script))?.default : null;
143
149
  return {
144
150
  fileHash: m.fileHash,
145
151
  migrator
@@ -147,6 +153,7 @@ const loadMigrationFunctions = async (sortedMigrationEntries, currentPlanVersion
147
153
  }));
148
154
  if (!cacheValid) {
149
155
  (0, _cachedPlannedVersion.setCachedMigratorFunctions)(migrationFunctions);
156
+ (0, _cachedPlannedVersion.setCachedPlannedVersion)(nextVersion);
150
157
  }
151
158
  return (0, _lodash.merge)(sortedMigrationEntries, migrationFunctions);
152
159
  };
@@ -253,8 +260,7 @@ const getPlannedMigrations = async ({
253
260
  }];
254
261
  await (0, _database.insertVersions)(database, pgpHelpers, entity, versionRecord);
255
262
  }
256
- const plannedMigrationsWithFunctions = importModule ? await loadMigrationFunctions(plannedMigrationsWithFileEntries, nextVersion, importModule) : plannedMigrationsWithFileEntries;
257
- (0, _cachedPlannedVersion.setCachedPlannedVersion)(nextVersion); //Must set _after_ loading migration functions
263
+ const plannedMigrationsWithFunctions = await loadMigrationFunctions(plannedMigrationsWithHistory, nextVersion, importModule);
258
264
  return {
259
265
  plannedMigrations: plannedMigrationsWithFunctions,
260
266
  nextVersion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/node-json-migrator",
3
- "version": "2.3.7-beta-1",
3
+ "version": "2.3.7-beta-3",
4
4
  "description": "A library for JSON migrations",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/node-postgresql-migrator",
6
6
  "bugs": {