Skip to content

Commit 1daad10

Browse files
authored
fix: use immutable pgcrypto digest (#480)
1 parent ebc6917 commit 1daad10

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

  • packages/database_v2/migrations/default/1632668838948_uri-hash

packages/database_v2/migrations/default/1632668838948_uri-hash/up.sql

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
BEGIN;
2+
CREATE EXTENSION IF NOT EXISTS pgcrypto;
23

34
--- NFT Asset
45

56
-- Create a derived column
67
ALTER TABLE nft_asset
78
ADD COLUMN token_uri_hash bytea
8-
GENERATED ALWAYS AS (sha256(convert_to(token_uri, 'utf-8')))
9+
GENERATED ALWAYS AS (digest(token_uri, 'sha256'))
910
STORED;
1011

1112
-- Remove primary key constraint
@@ -25,7 +26,7 @@ ALTER TABLE nft
2526

2627
-- Populate column with hashes
2728
UPDATE nft
28-
SET token_uri_hash = sha256(convert_to(token_uri, 'utf-8'));
29+
SET token_uri_hash = digest(token_uri, 'sha256');
2930

3031
-- Make token_uri_hash non-nullable.
3132
ALTER TABLE nft
@@ -40,7 +41,7 @@ ALTER TABLE nft
4041
-- Create a derived column
4142
ALTER TABLE resource
4243
ADD COLUMN uri_hash bytea
43-
GENERATED ALWAYS AS (sha256(convert_to(uri, 'utf-8')))
44+
GENERATED ALWAYS AS (digest(uri, 'sha256'))
4445
STORED;
4546

4647
-- Make token_uri_hash non-nullable.
@@ -63,7 +64,7 @@ ALTER TABLE nft_metadata
6364

6465
-- Populate column with hashes
6566
UPDATE nft_metadata
66-
SET image_uri_hash = sha256(convert_to(image_uri, 'utf-8'));
67+
SET image_uri_hash = digest(image_uri, 'sha256');
6768

6869
-- Make image_uri_hash non-nullable.
6970
ALTER TABLE nft_metadata
@@ -81,7 +82,7 @@ ALTER TABLE other_nft_resources
8182

8283
-- Populate column with hashes
8384
UPDATE other_nft_resources
84-
SET resource_uri_hash = sha256(convert_to(resource_uri, 'utf-8'));
85+
SET resource_uri_hash = digest(resource_uri, 'sha256');
8586

8687
-- Make token_uri_hash non-nullable.
8788
ALTER TABLE other_nft_resources

0 commit comments

Comments
 (0)