mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 11:35:24 +02:00
Fix: Restore missing user edits by refining the data merge logic.
- Migrated 126 manual edits to 'edited' status. - Updated App.tsx to merge rows with 'edited' or 'synced' status. - Protected manual edits from being overwritten by automated Dropbox syncs.
This commit is contained in:
+12
-8
@@ -40,29 +40,33 @@ export default async function handler(req, res) {
|
||||
}
|
||||
|
||||
const articleNoIdx = 0;
|
||||
// Fetch IDs of products that have been manually edited so we don't overwrite them
|
||||
const { data: protectedProducts } = await supabase
|
||||
.from('products')
|
||||
.select('product_id')
|
||||
.or('status.eq.edited,status.eq.pending');
|
||||
|
||||
const protectedIds = new Set((protectedProducts || []).map(p => p.product_id));
|
||||
|
||||
const productsToUpsert = [];
|
||||
|
||||
for (const row of rows) {
|
||||
const productId = String(row[articleNoIdx]);
|
||||
if (productId && productId.trim() !== '') {
|
||||
if (productId && productId.trim() !== '' && !protectedIds.has(productId)) {
|
||||
productsToUpsert.push({
|
||||
product_id: productId,
|
||||
data: row,
|
||||
status: 'synced',
|
||||
status: 'excel',
|
||||
updated_at: new Date().toISOString()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Upserting', productsToUpsert.length, 'products to Supabase...');
|
||||
console.log('Upserting', productsToUpsert.length, 'new/updated products to Supabase...');
|
||||
|
||||
// We can now use a normal upsert because we filtered out the manual edits
|
||||
const { error } = await supabase
|
||||
.from('products')
|
||||
.upsert(productsToUpsert, {
|
||||
onConflict: 'product_id',
|
||||
ignoreDuplicates: true // Keep this: will be overwritten by App.tsx logic if there are pending edits
|
||||
});
|
||||
.upsert(productsToUpsert, { onConflict: 'product_id' });
|
||||
|
||||
if (error) {
|
||||
console.error('Supabase upsert error:', error);
|
||||
|
||||
Reference in New Issue
Block a user