@oliasoft-open-source/node-json-migrator 5.6.0 → 5.6.1-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/dist/index.mjs +9 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4344,7 +4344,10 @@ const updateRecord = async (t, entityTableName, entityColumnNames, entityId, cur
|
|
|
4344
4344
|
$(versionColumn:name) = $(nextVersion)
|
|
4345
4345
|
${useEtag ? ", $(etagColumn:name) = $(etagColumn:name) + 1" : ""}
|
|
4346
4346
|
WHERE $(idColumn:name) = $(entityId)
|
|
4347
|
-
AND
|
|
4347
|
+
AND (
|
|
4348
|
+
$(versionColumn:name) = $(currentVersion)
|
|
4349
|
+
OR ($(versionColumn:name) IS NULL AND $(currentVersion) IS NULL)
|
|
4350
|
+
)
|
|
4348
4351
|
${useEtag ? "AND $(etagColumn:name) = $(etag)" : ""}
|
|
4349
4352
|
RETURNING *
|
|
4350
4353
|
`;
|
|
@@ -4836,7 +4839,7 @@ const validateConcurrency = (concurrency) => {
|
|
|
4836
4839
|
/**
|
|
4837
4840
|
* Migrate an entity record in the database
|
|
4838
4841
|
*/
|
|
4839
|
-
const migrateRecord = async ({ record, config, preparedPlan, loadHistoricalPlans, beforeMigrateRecord, afterMigrateRecord }) => {
|
|
4842
|
+
const migrateRecord = async ({ record, attempt, config, preparedPlan, loadHistoricalPlans, beforeMigrateRecord, afterMigrateRecord }) => {
|
|
4840
4843
|
const { dry } = config;
|
|
4841
4844
|
console.log(chalk.gray(` ${record.name}`));
|
|
4842
4845
|
try {
|
|
@@ -4862,7 +4865,7 @@ const migrateRecord = async ({ record, config, preparedPlan, loadHistoricalPlans
|
|
|
4862
4865
|
});
|
|
4863
4866
|
if (!dry) {
|
|
4864
4867
|
const nextRecord = await updateRecord(transaction, config?.entityTableName, config?.entityColumnNames, record.id, currentVersion, nextData, nextVersion, etag);
|
|
4865
|
-
if (!nextRecord) throw new Error(
|
|
4868
|
+
if (!nextRecord) throw new Error(`Failed to patch record with newest migration - The record was probably updated while migrating... Expected version=${JSON.stringify(currentVersion)}, etag=${JSON.stringify(etag)}.`);
|
|
4866
4869
|
await afterMigrateRecord({
|
|
4867
4870
|
currentRecord,
|
|
4868
4871
|
nextRecord,
|
|
@@ -4880,7 +4883,8 @@ const migrateRecord = async ({ record, config, preparedPlan, loadHistoricalPlans
|
|
|
4880
4883
|
error,
|
|
4881
4884
|
stackTrace: error?.stack
|
|
4882
4885
|
};
|
|
4883
|
-
|
|
4886
|
+
const retryStatus = attempt < MAX_ATTEMPTS ? "retrying" : "no retries left";
|
|
4887
|
+
console.log(chalk.red(` ${capitalize(config.entity)} migration with id ${record.id} failed: attempt ${attempt}/${MAX_ATTEMPTS}; ${retryStatus}.\n ${error?.stack}`));
|
|
4884
4888
|
return migrationErrorPayload;
|
|
4885
4889
|
}
|
|
4886
4890
|
};
|
|
@@ -4907,6 +4911,7 @@ const migrateRecords = async ({ recordList, config, preparedPlan, beforeMigrateR
|
|
|
4907
4911
|
if (attempt > 1) console.log(chalk.gray(`Retrying migration of ${record.name} (attempt ${attempt}/${MAX_ATTEMPTS}).`));
|
|
4908
4912
|
const migrationErrorPayload = await migrateRecord({
|
|
4909
4913
|
record,
|
|
4914
|
+
attempt,
|
|
4910
4915
|
config,
|
|
4911
4916
|
preparedPlan,
|
|
4912
4917
|
loadHistoricalPlans,
|
package/package.json
CHANGED