Skip to content

Commit e283f7a

Browse files
committed
fixed backfill logic
1 parent 2e41e38 commit e283f7a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

functions/process-image/handler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,17 @@ async function handleFileMode(
287287
`SELECT set_config('app.database_id', $1, true)`,
288288
[String(file.database_id)]
289289
);
290+
// Use COALESCE to handle NULL domain column: if NULL, build a
291+
// minimal object with key + versions; if not NULL, merge versions in.
290292
await sourceClient.query(
291293
`UPDATE ${file.source_table}
292294
SET ${file.source_column} = jsonb_set(
293-
${file.source_column}::jsonb,
295+
COALESCE(${file.source_column}::jsonb, jsonb_build_object('key', $3::text)),
294296
'{versions}',
295297
$1::jsonb
296298
)
297299
WHERE id = $2`,
298-
[JSON.stringify(versionsArray), file.source_id]
300+
[JSON.stringify(versionsArray), file.source_id, file.key]
299301
);
300302
await sourceClient.query('COMMIT');
301303
} catch (domainUpdateErr) {

0 commit comments

Comments
 (0)