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
+8 -1
View File
@@ -45,13 +45,20 @@ export default async function handler(req, res) {
.from('products') .from('products')
.select('product_id, status'); .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( const manuallyEditedIds = new Set(
(existingProducts || []) (existingProducts || [])
.filter(p => p.status === 'edited' || p.status === 'pending') .filter(p => p.status === 'edited' || p.status === 'pending')
.map(p => p.product_id) .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 = []; const productsToUpsert = [];
for (const row of rows) { for (const row of rows) {
const productId = String(row[articleNoIdx]); const productId = String(row[articleNoIdx]);