From ea403edb170600cb246e58445d073305e29cef73 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Sun, 5 Jan 2025 18:07:25 +0900 Subject: [PATCH] fix: update address not nil attributes Signed-off-by: Miles Zhang --- app/models/ckb_sync/new_node_data_processor.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index ae2134539..d27834518 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -355,7 +355,17 @@ def update_addresses_dao_info(addrs_deposit_info) is_depositor: address_info[:is_depositor], } end - Address.upsert_all(addresses_deposit_attributes, record_timestamps: true) if addresses_deposit_attributes.present? + if addresses_deposit_attributes.present? + Address.upsert_all( + addresses_deposit_attributes, + record_timestamps: true, + on_duplicate: Arel.sql( + "dao_deposit = COALESCE(EXCLUDED.dao_deposit, addresses.dao_deposit), " \ + "interest = COALESCE(EXCLUDED.interest, addresses.interest), " \ + "is_depositor = COALESCE(EXCLUDED.is_depositor, addresses.is_depositor)", + ), + ) + end end def update_or_create_udt_accounts!(local_block)