From f275dd57317b46bbe5ea119d6cc75e1b91c826f4 Mon Sep 17 00:00:00 2001 From: Aleksei Fedotov <102949797+alekseifedotov@users.noreply.github.com> Date: Wed, 15 May 2024 16:44:29 +0200 Subject: [PATCH] fix: startup with pre-defined values. (#35) When tx-sitter starts with pre-defined relayer in the config, it inserts records about it in the DB. When the tx-sitter restarts, it fails to insert the same record again with the following error message: > Error: error returned from database: duplicate key value violates unique constraint "networks_pkey" > > Caused by: > duplicate key value violates unique constraint "networks_pkey" After this commit if a conflicting record is detected, do nothing. --- src/db.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/db.rs b/src/db.rs index bdc010d..4cfe338 100644 --- a/src/db.rs +++ b/src/db.rs @@ -53,6 +53,7 @@ impl Database { r#" INSERT INTO relayers (id, name, chain_id, key_id, address) VALUES ($1, $2, $3, $4, $5) + ON CONFLICT DO NOTHING "#, ) .bind(id) @@ -969,6 +970,7 @@ impl Database { r#" INSERT INTO networks (chain_id, name) VALUES ($1, $2) + ON CONFLICT DO NOTHING "#, ) .bind(chain_id as i64) @@ -982,6 +984,7 @@ impl Database { VALUES ($1, $2, $3), ($1, $4, $5) + ON CONFLICT DO NOTHING "#, ) .bind(chain_id as i64) @@ -1043,6 +1046,7 @@ impl Database { r#" INSERT INTO api_keys (relayer_id, key_hash) VALUES ($1, $2) + ON CONFLICT DO NOTHING "#, ) .bind(relayer_id)