@oliasoft-open-source/node-json-migrator 5.6.4-beta-1 → 5.6.5

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/index.mjs +13 -8
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -4750,7 +4750,8 @@ const parseHistoricalPlan = (rawPlan, revision) => {
4750
4750
  plan
4751
4751
  };
4752
4752
  } catch {
4753
- console.warn(`Skipping invalid historical plan.json at commit ${revision.version}`);
4753
+ const detail = rawPlan.includes("\0") ? " (contains NUL bytes)" : "";
4754
+ console.warn(`Skipping invalid historical plan.json at commit ${revision.version}${detail}`);
4754
4755
  return null;
4755
4756
  }
4756
4757
  };
@@ -4791,18 +4792,22 @@ const getExecutedMigrationsFromVersion = async (database, pgpHelpers, entity, di
4791
4792
  version: currentVersion
4792
4793
  });
4793
4794
  if (migrations !== null) return migrations;
4794
- let planFromVersion = null;
4795
4795
  console.warn(chalk.yellow(`Version not found in ${entity}_version table, trying git history instead`));
4796
4796
  const { historicalPlans } = await loadHistoricalPlans(`${directory}/plan.json`);
4797
- if (historicalPlans.length) {
4798
- await insertVersions(database, pgpHelpers, entity, historicalPlans);
4799
- planFromVersion = historicalPlans.find((p) => p.version === currentVersion)?.plan || null;
4800
- }
4801
- if (planFromVersion !== null) return parseAndValidatePlan(planFromVersion, `${entity}_versions table`);
4802
- else {
4797
+ const planFromVersion = historicalPlans.find((p) => p.version === currentVersion)?.plan;
4798
+ if (planFromVersion === void 0) {
4803
4799
  console.error(chalk.red(historyError));
4804
4800
  throw new Error(`Unable to migrate, could not find version history`);
4805
4801
  }
4802
+ const executedMigrations = parseAndValidatePlan(planFromVersion, `${entity} plan.json from Git history`);
4803
+ try {
4804
+ await database.tx(async (transaction) => {
4805
+ await insertVersions(transaction, pgpHelpers, entity, historicalPlans);
4806
+ });
4807
+ } catch (error) {
4808
+ console.warn(`Unable to cache Git history for ${entity} (${historicalPlans.length} plans, code: ${error?.code ?? "unknown"}, message: ${error?.message ?? error}). Using the Git plan for version ${currentVersion}.`);
4809
+ }
4810
+ return executedMigrations;
4806
4811
  }
4807
4812
  };
4808
4813
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/node-json-migrator",
3
- "version": "5.6.4-beta-1",
3
+ "version": "5.6.5",
4
4
  "description": "A library for JSON migrations",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/node-json-migrator",
6
6
  "bugs": {