fix: process deletes before adds in CLI sync push to avoid conflicts (#8148)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-02-28 18:05:33 +00:00
committed by GitHub
parent d933446a9e
commit 278983c4fd

View File

@@ -1496,11 +1496,21 @@ async function compareDynFSElement(
}
}
changes.sort((a, b) =>
getOrderFromPath(a.path) == getOrderFromPath(b.path)
? a.path.localeCompare(b.path)
: getOrderFromPath(a.path) - getOrderFromPath(b.path),
);
changes.sort((a, b) => {
const orderA = getOrderFromPath(a.path);
const orderB = getOrderFromPath(b.path);
if (orderA !== orderB) {
return orderA - orderB;
}
// Within the same entity type, process deletes before adds/edits
// to avoid conflicts (e.g. unique path constraints on triggers)
const deletePriority = (name: string) => (name === "deleted" ? 0 : 1);
const dp = deletePriority(a.name) - deletePriority(b.name);
if (dp !== 0) {
return dp;
}
return a.path.localeCompare(b.path);
});
return changes;
}