From 197c4d4f3982ef4ca65732a971e8026e72ca72f6 Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Mon, 19 Jun 2023 11:56:44 -0400 Subject: [PATCH] Fix uniqueness check in InsertOrGetFFI to match indexes When guessing the reason for an insert conflict, the query needs to exactly match the configured database indexes. That means that the "name" and "networkName" queries need to both include "version" as well, otherwise we risk grabbing a row that isn't actually a conflict. Signed-off-by: Andrew Richardson --- internal/database/sqlcommon/ffi_sql.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/database/sqlcommon/ffi_sql.go b/internal/database/sqlcommon/ffi_sql.go index 468993131..c0461d36e 100644 --- a/internal/database/sqlcommon/ffi_sql.go +++ b/internal/database/sqlcommon/ffi_sql.go @@ -133,8 +133,8 @@ func (s *SQLCommon) InsertOrGetFFI(ctx context.Context, ffi *fftypes.FFI) (exist sq.Eq{"namespace": ffi.Namespace}, sq.Or{ sq.Eq{"id": ffi.ID}, - sq.Eq{"name": ffi.Name}, - sq.Eq{"network_name": ffi.NetworkName}, + sq.Eq{"name": ffi.Name, "version": ffi.Version}, + sq.Eq{"network_name": ffi.NetworkName, "version": ffi.Version}, }, }) if queryErr != nil || existing != nil {