@oliasoft-open-source/node-json-migrator 5.1.0 → 5.2.0
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.
- package/README.md +23 -23
- package/package.json +30 -31
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ npm install --save git+https://gitlab.com/oliasoft-open-source/node-json-migrato
|
|
|
36
36
|
Use the `createMigration()` function to generate a skeleton migration script, for example:
|
|
37
37
|
|
|
38
38
|
```javascript
|
|
39
|
-
import {createMigration} from 'node-json-migrator';
|
|
39
|
+
import { createMigration } from 'node-json-migrator';
|
|
40
40
|
|
|
41
41
|
const directory = 'json-migrations';
|
|
42
42
|
const description = 'add-panda';
|
|
@@ -57,9 +57,9 @@ For example, after editing, the scripts might look like this:
|
|
|
57
57
|
```javascript
|
|
58
58
|
import { produce } from 'immer';
|
|
59
59
|
|
|
60
|
-
export default (payload
|
|
61
|
-
|
|
62
|
-
});
|
|
60
|
+
export default (payload = produce(state, (draft) => {
|
|
61
|
+
draft.panda = 'Elliot';
|
|
62
|
+
}));
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
**json-migrations/plan.json** (defines the migration execution plan)
|
|
@@ -74,32 +74,32 @@ export default (payload) = produce(state, (draft) => {
|
|
|
74
74
|
]
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
Note: the `fileHash` property is the SHA256 hash of the migration file content. You don't have to manually maintain
|
|
77
|
+
Note: the `fileHash` property is the SHA256 hash of the migration file content. You don't have to manually maintain
|
|
78
78
|
that, the tool will sync it automatically for you.
|
|
79
79
|
|
|
80
80
|
## Running migrations
|
|
81
81
|
|
|
82
|
-
In your application source code, import and call the `migrate()` function. The simplest usage (runs all migrations)
|
|
82
|
+
In your application source code, import and call the `migrate()` function. The simplest usage (runs all migrations)
|
|
83
83
|
is:
|
|
84
84
|
|
|
85
85
|
```javascript
|
|
86
|
-
import {migrate} from 'node-json-migrator';
|
|
86
|
+
import { migrate } from 'node-json-migrator';
|
|
87
87
|
|
|
88
|
-
const {nextPayload} = await migrate({
|
|
88
|
+
const { nextPayload } = await migrate({
|
|
89
89
|
payload: {},
|
|
90
90
|
config: {
|
|
91
|
-
directory: 'json-migrations'
|
|
92
|
-
}
|
|
91
|
+
directory: 'json-migrations',
|
|
92
|
+
},
|
|
93
93
|
});
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
Normally you want to track payload versions, and only execute pending migrations. To do this, you need to connect to a
|
|
96
|
+
Normally you want to track payload versions, and only execute pending migrations. To do this, you need to connect to a
|
|
97
97
|
PostgreSQL database and pass a
|
|
98
98
|
connected [pg-promise database object](http://vitaly-t.github.io/pg-promise/). Then it looks like this:
|
|
99
99
|
|
|
100
100
|
```javascript
|
|
101
101
|
import pgPromise from 'pg-promise';
|
|
102
|
-
import {migrate} from 'node-json-migrator';
|
|
102
|
+
import { migrate } from 'node-json-migrator';
|
|
103
103
|
|
|
104
104
|
//connect to the database somewhere in the database layer
|
|
105
105
|
const pgp = pgPromise({});
|
|
@@ -110,14 +110,14 @@ database.connect();
|
|
|
110
110
|
//if we know the current payload version, we can run only the newer, pending migration scripts
|
|
111
111
|
const currentPayloadVersion = undefined;
|
|
112
112
|
|
|
113
|
-
const {nextPayload, nextVersion} = await migrate({
|
|
113
|
+
const { nextPayload, nextVersion } = await migrate({
|
|
114
114
|
payload: {},
|
|
115
115
|
config: {
|
|
116
116
|
directory: 'json-migrations',
|
|
117
117
|
database, //connected database object
|
|
118
118
|
pgpHelpers, //pg-promise helpers: https://vitaly-t.github.io/pg-promise/helpers.html
|
|
119
|
-
version: currentPayloadVersion
|
|
120
|
-
}
|
|
119
|
+
version: currentPayloadVersion,
|
|
120
|
+
},
|
|
121
121
|
});
|
|
122
122
|
```
|
|
123
123
|
|
|
@@ -127,7 +127,7 @@ const {nextPayload, nextVersion} = await migrate({
|
|
|
127
127
|
config = {
|
|
128
128
|
dry: true, //execute without writing to database tables or files
|
|
129
129
|
force: true, //execute bypassing some validation warnings
|
|
130
|
-
}
|
|
130
|
+
};
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
## Usage Rules
|
|
@@ -147,23 +147,23 @@ If you release a bad migration script, there is an escape-hatch for backfitting
|
|
|
147
147
|
|
|
148
148
|
- rename the faulty script to `.skip.js` (or `.skip2.js` if it happened more than once)
|
|
149
149
|
- add a new migration file with the original filename, to replace it (fix bug in new file)
|
|
150
|
-
- the replacement script will
|
|
150
|
+
- the replacement script will _not_ re-execute on payloads that already had the original script applied
|
|
151
151
|
|
|
152
152
|
Or, you can backfit a script earlier in the sequence
|
|
153
153
|
|
|
154
154
|
- add a new migration file
|
|
155
155
|
- set its sequence to for example `1.1` (subsequence number)
|
|
156
|
-
- the backfitted script
|
|
156
|
+
- the backfitted script _will_ execute one time on all payloads
|
|
157
157
|
|
|
158
158
|
# How to contribute
|
|
159
159
|
|
|
160
160
|
Contribution is welcome via [issue tickets](https://gitlab.com/oliasoft-open-source/node-json-migrator/-/issues)
|
|
161
161
|
and [merge requests](https://gitlab.com/oliasoft-open-source/node-json-migrator/-/merge_requests).
|
|
162
162
|
|
|
163
|
-
- coding style (
|
|
163
|
+
- coding style (Oxlint and Oxfmt) is mandatory (applied via pre-commit hook)
|
|
164
164
|
- to test: `npm run test`
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
- database is mocked with [pg-mem](https://github.com/oguimbal/pg-mem) (in-memory database)
|
|
166
|
+
- filesystem is mocked [mock-fs](https://github.com/tschaub/mock-fs)
|
|
167
|
+
- coverage reports are in `test/coverage` (not committed)
|
|
168
168
|
- to build: `npm run buld` (this transpile a production build to the `dist` directory)
|
|
169
|
-
|
|
169
|
+
- the build `dist` directory should be committed
|
package/package.json
CHANGED
|
@@ -1,55 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oliasoft-open-source/node-json-migrator",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "A library for JSON migrations",
|
|
5
5
|
"homepage": "https://oliasoft-open-source.gitlab.io/node-json-migrator",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://gitlab.com/oliasoft-open-source/node-json-migrator/issues"
|
|
8
8
|
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Oliasoft AS and contributors",
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
13
|
"url": "git+https://gitlab.com/oliasoft-open-source/node-json-migrator.git"
|
|
12
14
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
15
18
|
"type": "module",
|
|
19
|
+
"main": "./dist/index.mjs",
|
|
20
|
+
"module": "./dist/index.mjs",
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
16
22
|
"exports": {
|
|
17
23
|
".": {
|
|
18
24
|
"types": "./dist/index.d.mts",
|
|
19
25
|
"import": "./dist/index.mjs"
|
|
20
26
|
}
|
|
21
27
|
},
|
|
22
|
-
"main": "./dist/index.mjs",
|
|
23
|
-
"module": "./dist/index.mjs",
|
|
24
|
-
"types": "./dist/index.d.mts",
|
|
25
|
-
"files": [
|
|
26
|
-
"dist"
|
|
27
|
-
],
|
|
28
|
-
"devEngines": {
|
|
29
|
-
"packageManager": {
|
|
30
|
-
"name": "pnpm",
|
|
31
|
-
"version": "11.3.0",
|
|
32
|
-
"onFail": "download"
|
|
33
|
-
},
|
|
34
|
-
"runtime": {
|
|
35
|
-
"name": "node",
|
|
36
|
-
"version": "26.3.0",
|
|
37
|
-
"onFail": "download"
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
"lint-staged": {
|
|
41
|
-
"**/*.{ts,js}": "oxlint --fix",
|
|
42
|
-
"**/*.{ts,js,json}": [
|
|
43
|
-
"prettier --write"
|
|
44
|
-
]
|
|
45
|
-
},
|
|
46
28
|
"dependencies": {
|
|
47
29
|
"immer": "^11.1.4",
|
|
48
30
|
"pg-promise": "^12.6.1"
|
|
49
31
|
},
|
|
50
32
|
"devDependencies": {
|
|
51
33
|
"@oxc-node/core": "^0.0.35",
|
|
52
|
-
"@prettier/plugin-oxc": "^0.1.3",
|
|
53
34
|
"@types/mock-fs": "^4.13.4",
|
|
54
35
|
"@types/node": "^25.5.0",
|
|
55
36
|
"ajv": "^8.18.0",
|
|
@@ -60,9 +41,9 @@
|
|
|
60
41
|
"husky": "^9.1.7",
|
|
61
42
|
"lint-staged": "^16.4.0",
|
|
62
43
|
"mock-fs": "^5.5.0",
|
|
44
|
+
"oxfmt": "^0.61.0",
|
|
63
45
|
"oxlint": "^1.56.0",
|
|
64
46
|
"pg-mem": "^3.0.14",
|
|
65
|
-
"prettier": "3.8.1",
|
|
66
47
|
"strip-ansi": "^7.2.0",
|
|
67
48
|
"tsdown": "^0.21.4",
|
|
68
49
|
"typescript": "^5.9.3",
|
|
@@ -71,11 +52,29 @@
|
|
|
71
52
|
"peerDependencies": {
|
|
72
53
|
"pg-promise": "^11 || ^12"
|
|
73
54
|
},
|
|
55
|
+
"lint-staged": {
|
|
56
|
+
"*": [
|
|
57
|
+
"oxlint --fix",
|
|
58
|
+
"oxfmt"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"devEngines": {
|
|
62
|
+
"packageManager": {
|
|
63
|
+
"name": "pnpm",
|
|
64
|
+
"version": "11.3.0",
|
|
65
|
+
"onFail": "download"
|
|
66
|
+
},
|
|
67
|
+
"runtime": {
|
|
68
|
+
"name": "node",
|
|
69
|
+
"version": "26.3.0",
|
|
70
|
+
"onFail": "download"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
74
73
|
"scripts": {
|
|
75
74
|
"build": "tsdown",
|
|
76
75
|
"compile:validators": "node --disable-warning=DEP0205 --import @oxc-node/core/register scripts/compile-validators.ts",
|
|
77
|
-
"format:check": "
|
|
78
|
-
"format:fix": "
|
|
76
|
+
"format:check": "oxfmt --check",
|
|
77
|
+
"format:fix": "oxfmt",
|
|
79
78
|
"lint:check": "oxlint",
|
|
80
79
|
"lint:fix": "oxlint --fix",
|
|
81
80
|
"test": "pnpm run test:unit && pnpm run test:integration",
|