@oliasoft-open-source/node-json-migrator 2.3.3 → 2.3.4-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.
@@ -8,16 +8,29 @@ var _chalk = _interopRequireDefault(require("chalk"));
8
8
  var _plan = require("../plan/plan");
9
9
  var _executed = require("../executed/executed");
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ const shortHash = hash => hash ? hash.substring(0, 8) : '';
11
12
  const getPendingMigrations = ({
12
13
  plannedMigrations,
13
14
  executedMigrations,
14
- printPendingFileNames = false
15
+ printPendingFileNames = false,
16
+ force
15
17
  }) => {
16
- const executedMigrationFileNames = executedMigrations.map(e => e.fileName);
17
- const pendingMigrations = plannedMigrations.filter(m => !executedMigrationFileNames.includes(m.fileName));
18
+ const pendingMigrations = plannedMigrations.filter(m => {
19
+ const executed = executedMigrations.find(e => e?.fileName === m.fileName);
20
+ const skippedFileHashes = m?.skippedFileHashes;
21
+ const isSkippedAndPreviouslyExecuted = skippedFileHashes?.includes(executed?.fileHash);
22
+ /*
23
+ - always execute migrations that have never been executed
24
+ - re-execute migrations only when all are true:
25
+ - fileHash has changed
26
+ - force flag is active
27
+ - the migration was not previously executed and skipped (see .skip feature for patching migration bugs)
28
+ */
29
+ return executed === undefined || executed?.fileHash !== m?.fileHash && force && !isSkippedAndPreviouslyExecuted;
30
+ });
18
31
  if (printPendingFileNames) {
19
32
  pendingMigrations.forEach(m => {
20
- console.log(_chalk.default.gray(` ${m.fileName}`));
33
+ console.log(_chalk.default.gray(` ${m.fileName} ${shortHash(m?.fileHash)}`));
21
34
  });
22
35
  }
23
36
  return pendingMigrations.map(m => ({
@@ -36,7 +49,8 @@ const getPendingMigrators = async ({
36
49
  entity,
37
50
  version,
38
51
  plan,
39
- printPendingFileNames
52
+ printPendingFileNames,
53
+ force
40
54
  } = config;
41
55
  const {
42
56
  plannedMigrations,
@@ -48,7 +62,8 @@ const getPendingMigrators = async ({
48
62
  const pendingMigrators = getPendingMigrations({
49
63
  plannedMigrations,
50
64
  executedMigrations,
51
- printPendingFileNames
65
+ printPendingFileNames,
66
+ force
52
67
  });
53
68
  return {
54
69
  pendingMigrators,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/node-json-migrator",
3
- "version": "2.3.3",
3
+ "version": "2.3.4-beta-2",
4
4
  "description": "A library for JSON migrations",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/node-postgresql-migrator",
6
6
  "bugs": {