Skip to content

Commit

Permalink
sqlc/migrations: add new unique key to assets table
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guggero committed Jun 24, 2024
1 parent 1083cf1 commit aa8b251
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions tapdb/sqlc/migrations/000020_asset_unique_key.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP INDEX IF EXISTS assets_genesis_id_script_key_id_anchor_utxo_id_unique;
4 changes: 4 additions & 0 deletions tapdb/sqlc/migrations/000020_asset_unique_key.up.sql
Original file line number Diff line number Diff line change
@@ -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
);

0 comments on commit aa8b251

Please sign in to comment.