@fachkraftfreund/n8n-nodes-supabase 1.3.7 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -206,6 +206,7 @@ async function handleBulkUpsert(supabase, itemCount) {
|
|
|
206
206
|
const deduplicate = this.getNodeParameter('deduplicateByConflict', 0, false);
|
|
207
207
|
(0, supabaseClient_1.validateTableName)(table);
|
|
208
208
|
let rows = collectRowData(this, itemCount);
|
|
209
|
+
console.log(`[Supabase UPSERT ${table}] rows=${rows.length}, onConflict="${onConflict}", deduplicate=${deduplicate}`);
|
|
209
210
|
const options = {};
|
|
210
211
|
if (onConflict)
|
|
211
212
|
options.onConflict = onConflict;
|
|
@@ -215,16 +216,28 @@ async function handleBulkUpsert(supabase, itemCount) {
|
|
|
215
216
|
console.log(`[Supabase UPSERT ${table}] dedup by "${onConflict}": ${before} → ${rows.length} rows`);
|
|
216
217
|
}
|
|
217
218
|
const returnData = [];
|
|
219
|
+
const duplicateError = 'cannot affect row a second time';
|
|
218
220
|
for (let offset = 0; offset < rows.length; offset += BULK_BATCH_SIZE) {
|
|
219
|
-
|
|
221
|
+
let batch = rows.slice(offset, offset + BULK_BATCH_SIZE);
|
|
220
222
|
const batchLabel = `UPSERT ${table} batch ${Math.floor(offset / BULK_BATCH_SIZE) + 1}`;
|
|
221
223
|
const data = await withRetry(async () => {
|
|
222
224
|
const { data, error } = await supabase
|
|
223
225
|
.from(table)
|
|
224
226
|
.upsert(batch, options)
|
|
225
227
|
.select();
|
|
226
|
-
if (error)
|
|
227
|
-
|
|
228
|
+
if (error) {
|
|
229
|
+
const msg = (0, supabaseClient_1.formatSupabaseError)(error);
|
|
230
|
+
if (msg.toLowerCase().includes(duplicateError) && onConflict) {
|
|
231
|
+
const before = batch.length;
|
|
232
|
+
batch = deduplicateByConflictKeys(batch, onConflict);
|
|
233
|
+
console.log(`[Supabase ${batchLabel}] duplicate-row error caught, dedup fallback: ${before} → ${batch.length} rows`);
|
|
234
|
+
const retry = await supabase.from(table).upsert(batch, options).select();
|
|
235
|
+
if (retry.error)
|
|
236
|
+
throw new Error((0, supabaseClient_1.formatSupabaseError)(retry.error));
|
|
237
|
+
return retry.data;
|
|
238
|
+
}
|
|
239
|
+
throw new Error(msg);
|
|
240
|
+
}
|
|
228
241
|
return data;
|
|
229
242
|
}, batchLabel);
|
|
230
243
|
if (Array.isArray(data)) {
|
|
@@ -245,6 +258,7 @@ async function handleBulkUpdate(supabase, itemCount) {
|
|
|
245
258
|
}
|
|
246
259
|
const deduplicate = this.getNodeParameter('deduplicateByConflict', 0, false);
|
|
247
260
|
let rows = collectRowData(this, itemCount);
|
|
261
|
+
console.log(`[Supabase UPDATE ${table}] rows=${rows.length}, matchColumn="${matchColumn}", deduplicate=${deduplicate}`);
|
|
248
262
|
for (let i = 0; i < rows.length; i++) {
|
|
249
263
|
const row = rows[i];
|
|
250
264
|
if (!row || row[matchColumn] === undefined) {
|
|
@@ -254,21 +268,31 @@ async function handleBulkUpdate(supabase, itemCount) {
|
|
|
254
268
|
if (deduplicate) {
|
|
255
269
|
const before = rows.length;
|
|
256
270
|
rows = deduplicateByConflictKeys(rows, matchColumn);
|
|
257
|
-
|
|
258
|
-
console.log(`[Supabase UPDATE ${table}] deduplicated input: ${before} → ${rows.length} rows by match column "${matchColumn}"`);
|
|
259
|
-
}
|
|
271
|
+
console.log(`[Supabase UPDATE ${table}] dedup by "${matchColumn}": ${before} → ${rows.length} rows`);
|
|
260
272
|
}
|
|
261
273
|
const returnData = [];
|
|
274
|
+
const duplicateError = 'cannot affect row a second time';
|
|
262
275
|
for (let offset = 0; offset < rows.length; offset += BULK_BATCH_SIZE) {
|
|
263
|
-
|
|
276
|
+
let batch = rows.slice(offset, offset + BULK_BATCH_SIZE);
|
|
264
277
|
const batchLabel = `UPDATE ${table} batch ${Math.floor(offset / BULK_BATCH_SIZE) + 1}`;
|
|
265
278
|
const data = await withRetry(async () => {
|
|
266
279
|
const { data, error } = await supabase
|
|
267
280
|
.from(table)
|
|
268
281
|
.upsert(batch, { onConflict: matchColumn })
|
|
269
282
|
.select();
|
|
270
|
-
if (error)
|
|
271
|
-
|
|
283
|
+
if (error) {
|
|
284
|
+
const msg = (0, supabaseClient_1.formatSupabaseError)(error);
|
|
285
|
+
if (msg.toLowerCase().includes(duplicateError)) {
|
|
286
|
+
const before = batch.length;
|
|
287
|
+
batch = deduplicateByConflictKeys(batch, matchColumn);
|
|
288
|
+
console.log(`[Supabase ${batchLabel}] duplicate-row error caught, dedup fallback: ${before} → ${batch.length} rows`);
|
|
289
|
+
const retry = await supabase.from(table).upsert(batch, { onConflict: matchColumn }).select();
|
|
290
|
+
if (retry.error)
|
|
291
|
+
throw new Error((0, supabaseClient_1.formatSupabaseError)(retry.error));
|
|
292
|
+
return retry.data;
|
|
293
|
+
}
|
|
294
|
+
throw new Error(msg);
|
|
295
|
+
}
|
|
272
296
|
return data;
|
|
273
297
|
}, batchLabel);
|
|
274
298
|
if (Array.isArray(data)) {
|
package/package.json
CHANGED