Preserve existing order metadata on empty upserts
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m21s

This commit is contained in:
Cauê Faleiros
2026-06-22 15:15:44 -03:00
parent 3568e48ce9
commit bd98348989
2 changed files with 92 additions and 35 deletions

View File

@@ -26,13 +26,13 @@ const upsertOrders = async (payload) => {
produto_descricao = EXCLUDED.produto_descricao,
quantidade = EXCLUDED.quantidade,
valor_unitario = EXCLUDED.valor_unitario,
cliente_fone = EXCLUDED.cliente_fone,
cliente_nome_fantasia = EXCLUDED.cliente_nome_fantasia,
id_vendedor = EXCLUDED.id_vendedor,
nome_vendedor = EXCLUDED.nome_vendedor,
marketplace = EXCLUDED.marketplace,
canal_venda = EXCLUDED.canal_venda,
numero_ecommerce = EXCLUDED.numero_ecommerce,
cliente_fone = COALESCE(NULLIF(EXCLUDED.cliente_fone, ''), orders.cliente_fone),
cliente_nome_fantasia = COALESCE(NULLIF(EXCLUDED.cliente_nome_fantasia, ''), orders.cliente_nome_fantasia),
id_vendedor = COALESCE(NULLIF(EXCLUDED.id_vendedor, ''), orders.id_vendedor),
nome_vendedor = COALESCE(NULLIF(EXCLUDED.nome_vendedor, ''), orders.nome_vendedor),
marketplace = COALESCE(NULLIF(EXCLUDED.marketplace, ''), orders.marketplace),
canal_venda = COALESCE(NULLIF(EXCLUDED.canal_venda, ''), orders.canal_venda),
numero_ecommerce = COALESCE(NULLIF(EXCLUDED.numero_ecommerce, ''), orders.numero_ecommerce),
created_at = CURRENT_TIMESTAMP
`;