From 1453a717e552850a43f2c5bf18c6ce3abdf9595d Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 24 Jun 2024 15:07:31 +0200 Subject: [PATCH] sqlc/migrations: add new unique key to assets table Fixes #691 by adding a unique constraint that will actually work. The assumption of the constraint is that there will never be an asset of the same asset ID with the same script key in the same anchor transaction output. This would be impossible anyway because the asset leaves would collide within the asset-level MS-SMT tree. So this unique key is safe to use as an upsert detection mechanism. --- tapdb/sqlc/migrations/000020_asset_unique_key.down.sql | 1 + tapdb/sqlc/migrations/000020_asset_unique_key.up.sql | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 tapdb/sqlc/migrations/000020_asset_unique_key.down.sql create mode 100644 tapdb/sqlc/migrations/000020_asset_unique_key.up.sql diff --git a/tapdb/sqlc/migrations/000020_asset_unique_key.down.sql b/tapdb/sqlc/migrations/000020_asset_unique_key.down.sql new file mode 100644 index 000000000..d491775ed --- /dev/null +++ b/tapdb/sqlc/migrations/000020_asset_unique_key.down.sql @@ -0,0 +1 @@ +DROP INDEX IF EXISTS assets_genesis_id_script_key_id_anchor_utxo_id_unique; diff --git a/tapdb/sqlc/migrations/000020_asset_unique_key.up.sql b/tapdb/sqlc/migrations/000020_asset_unique_key.up.sql new file mode 100644 index 000000000..c5d0f5581 --- /dev/null +++ b/tapdb/sqlc/migrations/000020_asset_unique_key.up.sql @@ -0,0 +1,4 @@ +CREATE UNIQUE INDEX assets_genesis_id_script_key_id_anchor_utxo_id_unique +ON assets ( + genesis_id, script_key_id, anchor_utxo_id +);