@oliasoft-open-source/node-json-migrator 5.6.5 → 5.7.0-beta-1
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 +9 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.mjs +15 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -181,6 +181,15 @@ and [merge requests](https://gitlab.com/oliasoft-open-source/node-json-migrator/
|
|
|
181
181
|
- to build: `npm run buld` (this transpile a production build to the `dist` directory)
|
|
182
182
|
- the build `dist` directory should be committed
|
|
183
183
|
|
|
184
|
+
## Migrating selected records
|
|
185
|
+
|
|
186
|
+
Pass `recordIds` to `migrateAll()` to restrict the usual migration eligibility checks to a list of IDs.
|
|
187
|
+
An empty list selects zero records. Omitting `recordIds` checks the entire entity table.
|
|
188
|
+
|
|
189
|
+
For larger selections, prepare the plan once with `getPlannedMigrations({ config })` and pass that
|
|
190
|
+
`preparedPlan` to each `migrateAll({ recordIds, preparedPlan, ... })` call. Use the same migration configuration and
|
|
191
|
+
plan for the duration of the run. Each call processes one selection with the usual transaction, retry and error handling.
|
|
192
|
+
|
|
184
193
|
## Concurrent database migrations
|
|
185
194
|
|
|
186
195
|
`migrateAll()` accepts `config.concurrency`, a positive integer that defaults to `1` (sequential processing).
|
package/dist/index.d.mts
CHANGED
|
@@ -42,6 +42,7 @@ type TRecordDetails = {
|
|
|
42
42
|
version: string;
|
|
43
43
|
currentPlan?: TPlan;
|
|
44
44
|
};
|
|
45
|
+
type TRecordIds = readonly TRecordDetails['id'][];
|
|
45
46
|
type TRecordDetailsList = TRecordDetails[];
|
|
46
47
|
type TEntityColumnNames = {
|
|
47
48
|
id: string;
|
|
@@ -110,6 +111,7 @@ declare const getPlannedMigrations: ({
|
|
|
110
111
|
nextVersion: string;
|
|
111
112
|
planHasChanged: boolean;
|
|
112
113
|
}>;
|
|
114
|
+
type TPreparedPlan = Awaited<ReturnType<typeof getPlannedMigrations>>;
|
|
113
115
|
//#endregion
|
|
114
116
|
//#region src/plan/planned-version.d.ts
|
|
115
117
|
declare const getPlannedVersion: ({
|
|
@@ -141,15 +143,19 @@ declare const migrate: ({
|
|
|
141
143
|
*/
|
|
142
144
|
declare const migrateAll: ({
|
|
143
145
|
config,
|
|
146
|
+
recordIds,
|
|
147
|
+
preparedPlan,
|
|
144
148
|
beforeMigrateRecord,
|
|
145
149
|
afterMigrateRecord,
|
|
146
150
|
onMigrationErrors
|
|
147
151
|
}: {
|
|
148
152
|
config: TConfig;
|
|
153
|
+
recordIds?: TRecordIds;
|
|
154
|
+
preparedPlan?: TPreparedPlan;
|
|
149
155
|
beforeMigrateRecord: TBeforeMigrateRecord;
|
|
150
156
|
afterMigrateRecord: TAfterMigrateRecord;
|
|
151
157
|
onMigrationErrors: TOnMigrationErrors;
|
|
152
|
-
}) => Promise<
|
|
158
|
+
}) => Promise<number>;
|
|
153
159
|
//#endregion
|
|
154
160
|
//#region src/pipe/pipe.d.ts
|
|
155
161
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -4299,7 +4299,8 @@ const filterRecordsWithNoPendingMigrations = ({ records, latestPlan }) => {
|
|
|
4299
4299
|
return latestPlan.some((p) => !currentHashes.has(p.fileHash));
|
|
4300
4300
|
});
|
|
4301
4301
|
};
|
|
4302
|
-
const getRecordList = async (db, entity, entityTableName, entityColumnNames, latestVersion, latestPlan) => {
|
|
4302
|
+
const getRecordList = async (db, entity, entityTableName, entityColumnNames, latestVersion, latestPlan, recordIds) => {
|
|
4303
|
+
if (recordIds?.length === 0) return [];
|
|
4303
4304
|
const query = `
|
|
4304
4305
|
SELECT
|
|
4305
4306
|
e.$(entityIdColumn:name) AS id,
|
|
@@ -4310,10 +4311,12 @@ const getRecordList = async (db, entity, entityTableName, entityColumnNames, lat
|
|
|
4310
4311
|
FROM $(entityTable:name) e
|
|
4311
4312
|
LEFT JOIN $(entityVersionsTable:name) v_current
|
|
4312
4313
|
ON v_current.version = e.$(entityVersionColumn:name)
|
|
4313
|
-
WHERE
|
|
4314
|
+
WHERE (
|
|
4314
4315
|
e.$(entityVersionColumn:name) IS NULL
|
|
4315
4316
|
OR e.$(entityVersionColumn:name) = ''
|
|
4316
4317
|
OR e.$(entityVersionColumn:name) <> $(latestVersion)
|
|
4318
|
+
)
|
|
4319
|
+
${recordIds === void 0 ? "" : "AND e.$(entityIdColumn:name) IN ($(recordIds:csv))"}
|
|
4317
4320
|
`;
|
|
4318
4321
|
const params = {
|
|
4319
4322
|
entityTable: entityTableName,
|
|
@@ -4322,7 +4325,8 @@ const getRecordList = async (db, entity, entityTableName, entityColumnNames, lat
|
|
|
4322
4325
|
entityNameColumn: entityColumnNames.name,
|
|
4323
4326
|
entityCreatedColumn: entityColumnNames.created,
|
|
4324
4327
|
entityVersionColumn: entityColumnNames.version,
|
|
4325
|
-
latestVersion
|
|
4328
|
+
latestVersion,
|
|
4329
|
+
recordIds
|
|
4326
4330
|
};
|
|
4327
4331
|
return filterRecordsWithNoPendingMigrations({
|
|
4328
4332
|
records: (await db.any(query, params)).map((r) => ({
|
|
@@ -4992,18 +4996,21 @@ const migrateRecords = async ({ recordList, config, preparedPlan, beforeMigrateR
|
|
|
4992
4996
|
/**
|
|
4993
4997
|
* Migrate all records (only use via command line interface)
|
|
4994
4998
|
*/
|
|
4995
|
-
const migrateAll = async ({ config, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors }) => {
|
|
4999
|
+
const migrateAll = async ({ config, recordIds, preparedPlan, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors }) => {
|
|
4996
5000
|
validateConcurrency(config.concurrency ?? 1);
|
|
4997
|
-
const
|
|
4998
|
-
const { validatedPlan: latestPlan, nextVersion: latestVersion } =
|
|
5001
|
+
const plan = preparedPlan ?? await PlanModule.getPlannedMigrations({ config });
|
|
5002
|
+
const { validatedPlan: latestPlan, nextVersion: latestVersion } = plan;
|
|
5003
|
+
const recordList = await getRecordList(config?.database, config?.entity, config?.entityTableName, config?.entityColumnNames, latestVersion, latestPlan, recordIds);
|
|
5004
|
+
if (recordIds !== void 0 && recordList.length === 0) return 0;
|
|
4999
5005
|
await migrateRecords({
|
|
5000
5006
|
config,
|
|
5001
|
-
preparedPlan,
|
|
5002
|
-
recordList
|
|
5007
|
+
preparedPlan: plan,
|
|
5008
|
+
recordList,
|
|
5003
5009
|
beforeMigrateRecord,
|
|
5004
5010
|
afterMigrateRecord,
|
|
5005
5011
|
onMigrationErrors
|
|
5006
5012
|
});
|
|
5013
|
+
return recordList.length;
|
|
5007
5014
|
};
|
|
5008
5015
|
//#endregion
|
|
5009
5016
|
//#region src/history/history.ts
|
package/package.json
CHANGED