@@ -1064,26 +1064,28 @@ ORDER BY assets_meta.meta_id;
1064
1064
1065
1065
-- name: UpsertSupplyPreCommit :one
1066
1066
-- Upsert a record into the supply_pre_commits table.
1067
- -- If a record with the same batch ID and tx output index already exists, update
1068
- -- the existing record. Otherwise, insert a new record.
1067
+ -- If a record with the same outpoint exists, update it; otherwise insert a new
1068
+ -- record.
1069
1069
WITH target_batch AS (
1070
- -- This CTE is used to fetch the ID of a batch, based on the serialized
1071
- -- internal key associated with the batch.
1072
1070
SELECT keys .key_id AS batch_id
1073
- FROM internal_keys keys
1071
+ FROM internal_keys AS keys
1074
1072
WHERE keys .raw_key = @batch_key
1075
1073
)
1076
1074
INSERT INTO supply_pre_commits (
1077
- batch_id, tx_output_index, taproot_internal_key_id, group_key, spent_by, outpoint
1075
+ batch_id, tx_output_index, taproot_internal_key_id, group_key, spent_by,
1076
+ outpoint
1078
1077
)
1079
1078
VALUES (
1080
- (SELECT batch_id FROM target_batch), @tx_output_index,
1081
- @taproot_internal_key_id, @group_key, sqlc .narg (' spent_by' ), sqlc .narg (' outpoint' )
1079
+ (SELECT batch_id FROM target_batch), @tx_output_index,
1080
+ @taproot_internal_key_id, @group_key, sqlc .narg (' spent_by' ),
1081
+ sqlc .narg (' outpoint' )
1082
1082
)
1083
- ON CONFLICT(batch_id, tx_output_index) DO UPDATE SET
1084
- -- The following fields are updated if a conflict occurs.
1083
+ ON CONFLICT(outpoint) DO UPDATE SET
1084
+ batch_id = EXCLUDED .batch_id ,
1085
+ tx_output_index = EXCLUDED .tx_output_index ,
1085
1086
taproot_internal_key_id = EXCLUDED .taproot_internal_key_id ,
1086
1087
group_key = EXCLUDED .group_key ,
1088
+ spent_by = EXCLUDED .spent_by ,
1087
1089
outpoint = EXCLUDED .outpoint
1088
1090
RETURNING id;
1089
1091
0 commit comments