Skip to content

Commit

Permalink
Fix auto-generated index
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Dec 20, 2024
1 parent d018345 commit 4ab4808
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 66 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion backend-rust/migrations/0001_initialize.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ CREATE INDEX scheduled_releases_idx ON scheduled_releases (account_index, releas
CREATE TABLE tokens (
-- An index/id for the token (row number).
index
BIGINT GENERATED ALWAYS AS IDENTITY
BIGINT
PRIMARY KEY,
-- Contract index that the token is associated with.
contract_index
Expand Down
19 changes: 11 additions & 8 deletions backend-rust/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2193,11 +2193,12 @@ async fn process_cis2_events(
// value in the database.
sqlx::query!(
"
INSERT INTO tokens (token_address, contract_index, contract_sub_index, \
INSERT INTO tokens (index, token_address, contract_index, contract_sub_index, \
total_supply, token_id, init_transaction_index)
VALUES ($1, $2, $3, $4, $5, $6)
ON CONFLICT (token_address)
DO UPDATE SET total_supply = EXCLUDED.total_supply",
VALUES ((SELECT COALESCE(MAX(index) + 1, 0) FROM tokens), $1, $2, $3, $4, $5, \
$6)
ON CONFLICT (token_address)
DO UPDATE SET total_supply = EXCLUDED.total_supply",
token_address,
contract_index,
contract_sub_index,
Expand Down Expand Up @@ -2257,9 +2258,10 @@ async fn process_cis2_events(
// database.
sqlx::query!(
"
INSERT INTO tokens (token_address, contract_index, contract_sub_index, \
INSERT INTO tokens (index, token_address, contract_index, contract_sub_index, \
total_supply, token_id, init_transaction_index)
VALUES ($1, $2, $3, $4, $5, $6)
VALUES ((SELECT COALESCE(MAX(index) + 1, 0) FROM tokens), $1, $2, $3, $4, $5, \
$6)
ON CONFLICT (token_address)
DO UPDATE SET total_supply = EXCLUDED.total_supply",
token_address,
Expand Down Expand Up @@ -2289,9 +2291,10 @@ async fn process_cis2_events(
// database.
sqlx::query!(
"
INSERT INTO tokens (token_address, contract_index, contract_sub_index, \
INSERT INTO tokens (index, token_address, contract_index, contract_sub_index, \
metadata_url, token_id, init_transaction_index)
VALUES ($1, $2, $3, $4, $5, $6)
VALUES ((SELECT COALESCE(MAX(index) + 1, 0) FROM tokens), $1, $2, $3, $4, $5, \
$6)
ON CONFLICT (token_address)
DO UPDATE SET metadata_url = EXCLUDED.metadata_url",
token_address,
Expand Down

0 comments on commit 4ab4808

Please sign in to comment.