@oliasoft-open-source/node-json-migrator 5.6.1-beta-1 → 5.6.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 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4344,6 +4344,11 @@ 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
|
+
-- OW-28171: Only update if the version has not changed since we read the record.
|
|
4348
|
+
-- In SQL, version = NULL is never true, so two NULL versions need an explicit check.
|
|
4349
|
+
-- IS NOT DISTINCT FROM provides null-safe equality, but pg-mem does not support it.
|
|
4350
|
+
-- The condition below selects the same rows in WHERE.
|
|
4351
|
+
-- https://www.postgresql.org/docs/current/functions-comparison.html
|
|
4347
4352
|
AND (
|
|
4348
4353
|
$(versionColumn:name) = $(currentVersion)
|
|
4349
4354
|
OR ($(versionColumn:name) IS NULL AND $(currentVersion) IS NULL)
|
|
@@ -4865,7 +4870,10 @@ const migrateRecord = async ({ record, attempt, config, preparedPlan, loadHistor
|
|
|
4865
4870
|
});
|
|
4866
4871
|
if (!dry) {
|
|
4867
4872
|
const nextRecord = await updateRecord(transaction, config?.entityTableName, config?.entityColumnNames, record.id, currentVersion, nextData, nextVersion, etag);
|
|
4868
|
-
if (!nextRecord)
|
|
4873
|
+
if (!nextRecord) {
|
|
4874
|
+
const expectedEtag = typeof etag === "number" ? `, etag=${JSON.stringify(etag)}` : "";
|
|
4875
|
+
throw new Error(`Failed to patch record with newest migration - The record was probably updated while migrating... Expected version=${JSON.stringify(currentVersion)}${expectedEtag}.`);
|
|
4876
|
+
}
|
|
4869
4877
|
await afterMigrateRecord({
|
|
4870
4878
|
currentRecord,
|
|
4871
4879
|
nextRecord,
|
|
@@ -4908,7 +4916,6 @@ const migrateRecords = async ({ recordList, config, preparedPlan, beforeMigrateR
|
|
|
4908
4916
|
let attempt = 0;
|
|
4909
4917
|
while (attempt < MAX_ATTEMPTS) {
|
|
4910
4918
|
attempt += 1;
|
|
4911
|
-
if (attempt > 1) console.log(chalk.gray(`Retrying migration of ${record.name} (attempt ${attempt}/${MAX_ATTEMPTS}).`));
|
|
4912
4919
|
const migrationErrorPayload = await migrateRecord({
|
|
4913
4920
|
record,
|
|
4914
4921
|
attempt,
|
package/package.json
CHANGED