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 <noreply@anthropic.com>
This commit is contained in:
Christian Vidal Wolf
2026-04-23 16:38:23 +02:00
co-authored by Claude Sonnet 4.6
parent 80f86cb83e
commit 59e4bdeb92
+9 -2
View File
@@ -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]);