@oliasoft-open-source/node-json-migrator 5.7.0-beta-1 → 5.7.0-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.
- package/README.md +3 -3
- package/dist/index.d.mts +9 -15
- package/dist/index.mjs +27 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -186,9 +186,9 @@ and [merge requests](https://gitlab.com/oliasoft-open-source/node-json-migrator/
|
|
|
186
186
|
Pass `recordIds` to `migrateAll()` to restrict the usual migration eligibility checks to a list of IDs.
|
|
187
187
|
An empty list selects zero records. Omitting `recordIds` checks the entire entity table.
|
|
188
188
|
|
|
189
|
-
For
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
For multiple batches, call `const migrateBatch = await prepareMigrationRun(options)` once with the configuration
|
|
190
|
+
and callbacks. Call `await migrateBatch(recordIds)` for each batch. The migrator prepares one plan for the run.
|
|
191
|
+
Each batch returns the number of eligible records.
|
|
192
192
|
|
|
193
193
|
## Concurrent database migrations
|
|
194
194
|
|
package/dist/index.d.mts
CHANGED
|
@@ -111,7 +111,6 @@ declare const getPlannedMigrations: ({
|
|
|
111
111
|
nextVersion: string;
|
|
112
112
|
planHasChanged: boolean;
|
|
113
113
|
}>;
|
|
114
|
-
type TPreparedPlan = Awaited<ReturnType<typeof getPlannedMigrations>>;
|
|
115
114
|
//#endregion
|
|
116
115
|
//#region src/plan/planned-version.d.ts
|
|
117
116
|
declare const getPlannedVersion: ({
|
|
@@ -138,23 +137,18 @@ declare const migrate: ({
|
|
|
138
137
|
}>;
|
|
139
138
|
//#endregion
|
|
140
139
|
//#region src/migrate-all/migrate-all.d.ts
|
|
141
|
-
|
|
142
|
-
* Migrate all records (only use via command line interface)
|
|
143
|
-
*/
|
|
144
|
-
declare const migrateAll: ({
|
|
145
|
-
config,
|
|
146
|
-
recordIds,
|
|
147
|
-
preparedPlan,
|
|
148
|
-
beforeMigrateRecord,
|
|
149
|
-
afterMigrateRecord,
|
|
150
|
-
onMigrationErrors
|
|
151
|
-
}: {
|
|
140
|
+
type MigrationRunOptions = {
|
|
152
141
|
config: TConfig;
|
|
153
|
-
recordIds?: TRecordIds;
|
|
154
|
-
preparedPlan?: TPreparedPlan;
|
|
155
142
|
beforeMigrateRecord: TBeforeMigrateRecord;
|
|
156
143
|
afterMigrateRecord: TAfterMigrateRecord;
|
|
157
144
|
onMigrationErrors: TOnMigrationErrors;
|
|
145
|
+
};
|
|
146
|
+
declare const prepareMigrationRun: (options: MigrationRunOptions) => Promise<(recordIds: TRecordIds) => Promise<number>>;
|
|
147
|
+
declare const migrateAll: ({
|
|
148
|
+
recordIds,
|
|
149
|
+
...options
|
|
150
|
+
}: MigrationRunOptions & {
|
|
151
|
+
recordIds?: TRecordIds;
|
|
158
152
|
}) => Promise<number>;
|
|
159
153
|
//#endregion
|
|
160
154
|
//#region src/pipe/pipe.d.ts
|
|
@@ -180,4 +174,4 @@ declare const printVersionHistory: ({
|
|
|
180
174
|
config: TConfig;
|
|
181
175
|
}) => Promise<void>;
|
|
182
176
|
//#endregion
|
|
183
|
-
export { type TAfterMigrateRecord, type TAfterMigrateRecordPayload, type TBeforeMigrateRecord, type TBeforeMigrateRecordPayload, type TConfig, type TEntityColumnNames, type TMetaData, type TMigration, type TMigrationErrorPayload, type TOnMigrationErrors, type TOnMigrationErrorsPayload, type TPayload, type TPlan, type TPlanEntry, type TRecord, type TRecordDetails, type TRecordDetailsList, checkMigrationPlan, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
|
|
177
|
+
export { type TAfterMigrateRecord, type TAfterMigrateRecordPayload, type TBeforeMigrateRecord, type TBeforeMigrateRecordPayload, type TConfig, type TEntityColumnNames, type TMetaData, type TMigration, type TMigrationErrorPayload, type TOnMigrationErrors, type TOnMigrationErrorsPayload, type TPayload, type TPlan, type TPlanEntry, type TRecord, type TRecordDetails, type TRecordDetailsList, checkMigrationPlan, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, prepareMigrationRun, printVersionHistory };
|
package/dist/index.mjs
CHANGED
|
@@ -4993,24 +4993,34 @@ const migrateRecords = async ({ recordList, config, preparedPlan, beforeMigrateR
|
|
|
4993
4993
|
console.log(chalk.yellow(`Completed ${config?.entity ?? "entity"} migrations (some failed)${config?.dry ? " [dry-run, no output written]" : ""} ✓`));
|
|
4994
4994
|
} else console.log(chalk.green(`Completed ${config?.entity ?? "entity"} migrations (success)${config?.dry ? " [dry-run, no output written]" : ""} ✓`));
|
|
4995
4995
|
};
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
*/
|
|
4999
|
-
const migrateAll = async ({ config, recordIds, preparedPlan, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors }) => {
|
|
4996
|
+
const prepareRun = async ({ config: runConfig, beforeMigrateRecord, afterMigrateRecord, onMigrationErrors }) => {
|
|
4997
|
+
const config = { ...runConfig };
|
|
5000
4998
|
validateConcurrency(config.concurrency ?? 1);
|
|
5001
|
-
const plan =
|
|
4999
|
+
const plan = await PlanModule.getPlannedMigrations({ config });
|
|
5002
5000
|
const { validatedPlan: latestPlan, nextVersion: latestVersion } = plan;
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5001
|
+
return async (recordIds) => {
|
|
5002
|
+
const recordList = await getRecordList(config?.database, config?.entity, config?.entityTableName, config?.entityColumnNames, latestVersion, latestPlan, recordIds);
|
|
5003
|
+
if (recordIds !== void 0 && recordList.length === 0) return 0;
|
|
5004
|
+
await migrateRecords({
|
|
5005
|
+
config,
|
|
5006
|
+
preparedPlan: plan,
|
|
5007
|
+
recordList,
|
|
5008
|
+
beforeMigrateRecord,
|
|
5009
|
+
afterMigrateRecord,
|
|
5010
|
+
onMigrationErrors
|
|
5011
|
+
});
|
|
5012
|
+
return recordList.length;
|
|
5013
|
+
};
|
|
5014
|
+
};
|
|
5015
|
+
const prepareMigrationRun = async (options) => {
|
|
5016
|
+
const migrateRecordsForRun = await prepareRun(options);
|
|
5017
|
+
return (recordIds) => {
|
|
5018
|
+
if (!Array.isArray(recordIds)) throw new TypeError("A migration batch requires an array of record IDs");
|
|
5019
|
+
return migrateRecordsForRun(recordIds);
|
|
5020
|
+
};
|
|
5021
|
+
};
|
|
5022
|
+
const migrateAll = async ({ recordIds, ...options }) => {
|
|
5023
|
+
return (await prepareRun(options))(recordIds);
|
|
5014
5024
|
};
|
|
5015
5025
|
//#endregion
|
|
5016
5026
|
//#region src/history/history.ts
|
|
@@ -5066,4 +5076,4 @@ const printVersionHistory = async ({ config }) => {
|
|
|
5066
5076
|
}
|
|
5067
5077
|
};
|
|
5068
5078
|
//#endregion
|
|
5069
|
-
export { checkMigrationPlan, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
|
|
5079
|
+
export { checkMigrationPlan, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, prepareMigrationRun, printVersionHistory };
|
package/package.json
CHANGED