From 59e4bdeb9213f44955d27e6b154a7ef394c9c7d4 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 23 Apr 2026 16:38:23 +0200 Subject: [PATCH] fix: protect products with history from being overwritten by Dropbox sync Products that have entries in products_history were edited at some point. If their status was accidentally reset to 'excel', the sync would overwrite their data. Now also check products_history to build the protected set. Co-Authored-By: Claude Sonnet 4.6 --- api/dropbox-sync.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/dropbox-sync.js b/api/dropbox-sync.js index eccf8bb..00ffd63 100644 --- a/api/dropbox-sync.js +++ b/api/dropbox-sync.js @@ -44,14 +44,21 @@ export default async function handler(req, res) { const { data: existingProducts } = await supabase .from('products') .select('product_id, status'); - - // Only skip if status is 'edited' or 'pending' (manual edits) + + // Protect products with status 'edited' or 'pending' const manuallyEditedIds = new Set( (existingProducts || []) .filter(p => p.status === 'edited' || p.status === 'pending') .map(p => p.product_id) ); + // Also protect any product that has history entries — they were edited at some point. + // If their status was accidentally reset to 'excel', this restores protection. + const { data: historyProducts } = await supabase + .from('products_history') + .select('product_id'); + (historyProducts || []).forEach(h => manuallyEditedIds.add(h.product_id)); + const productsToUpsert = []; for (const row of rows) { const productId = String(row[articleNoIdx]);