From 278983c4fd38d67a14a8c208178c04db05ee1880 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 28 Feb 2026 18:05:33 +0000 Subject: [PATCH] fix: process deletes before adds in CLI sync push to avoid conflicts (#8148) Co-authored-by: Claude Opus 4.6 --- cli/src/commands/sync/sync.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cli/src/commands/sync/sync.ts b/cli/src/commands/sync/sync.ts index 99a07d1f5d..6d4a359600 100644 --- a/cli/src/commands/sync/sync.ts +++ b/cli/src/commands/sync/sync.ts @@ -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; }