Skip to content

Commit

Permalink
Store jsonb extra_metadata correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
radazen committed Jul 1, 2024
1 parent 53bd520 commit 37297fb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
40 changes: 24 additions & 16 deletions db/gen/mirrordb/batch.go

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

24 changes: 12 additions & 12 deletions db/queries/mirror/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ token_insert as (
@last_sale,
@first_created,
@rarity,
@extra_metadata::jsonb,
@extra_metadata,
@image_properties,
@video_properties,
@audio_properties,
Expand All @@ -328,7 +328,7 @@ token_insert as (
@kafka_offset,
@kafka_partition,
@kafka_timestamp,
@extra_metadata,
@extra_metadata_jsonb::jsonb,
now()
where @should_upsert::bool
on conflict (simplehash_kafka_key) do update
Expand Down Expand Up @@ -364,7 +364,7 @@ token_insert as (
kafka_offset = excluded.kafka_offset,
kafka_partition = excluded.kafka_partition,
kafka_timestamp = excluded.kafka_timestamp,
extra_metadata_jsonb = excluded.extra_metadata::jsonb,
extra_metadata_jsonb = excluded.extra_metadata_jsonb,
last_metadata_conversion = now()
)
select @simplehash_nft_id::text
Expand Down Expand Up @@ -454,7 +454,7 @@ token_insert as (
@last_sale,
@first_created,
@rarity,
@extra_metadata::jsonb,
@extra_metadata,
@image_properties,
@video_properties,
@audio_properties,
Expand All @@ -464,7 +464,7 @@ token_insert as (
@kafka_offset,
@kafka_partition,
@kafka_timestamp,
@extra_metadata,
@extra_metadata_jsonb::jsonb,
now()
where @should_upsert::bool
on conflict (simplehash_kafka_key) do update
Expand Down Expand Up @@ -500,7 +500,7 @@ token_insert as (
kafka_offset = excluded.kafka_offset,
kafka_partition = excluded.kafka_partition,
kafka_timestamp = excluded.kafka_timestamp,
extra_metadata_jsonb = excluded.extra_metadata::jsonb,
extra_metadata_jsonb = excluded.extra_metadata_jsonb,
last_metadata_conversion = now()
)
select @simplehash_nft_id::text
Expand Down Expand Up @@ -590,7 +590,7 @@ token_insert as (
@last_sale,
@first_created,
@rarity,
@extra_metadata::jsonb,
@extra_metadata,
@image_properties,
@video_properties,
@audio_properties,
Expand All @@ -600,7 +600,7 @@ token_insert as (
@kafka_offset,
@kafka_partition,
@kafka_timestamp,
@extra_metadata,
@extra_metadata_jsonb::jsonb,
now()
where @should_upsert::bool
on conflict (simplehash_kafka_key) do update
Expand Down Expand Up @@ -636,7 +636,7 @@ token_insert as (
kafka_offset = excluded.kafka_offset,
kafka_partition = excluded.kafka_partition,
kafka_timestamp = excluded.kafka_timestamp,
extra_metadata_jsonb = excluded.extra_metadata::jsonb,
extra_metadata_jsonb = excluded.extra_metadata_jsonb,
last_metadata_conversion = now()
)
select @simplehash_nft_id::text
Expand Down Expand Up @@ -726,7 +726,7 @@ token_insert as (
@last_sale,
@first_created,
@rarity,
@extra_metadata::jsonb,
@extra_metadata,
@image_properties,
@video_properties,
@audio_properties,
Expand All @@ -736,7 +736,7 @@ token_insert as (
@kafka_offset,
@kafka_partition,
@kafka_timestamp,
@extra_metadata,
@extra_metadata_jsonb::jsonb,
now()
where @should_upsert::bool
on conflict (simplehash_kafka_key) do update
Expand Down Expand Up @@ -772,7 +772,7 @@ token_insert as (
kafka_offset = excluded.kafka_offset,
kafka_partition = excluded.kafka_partition,
kafka_timestamp = excluded.kafka_timestamp,
extra_metadata_jsonb = excluded.extra_metadata::jsonb,
extra_metadata_jsonb = excluded.extra_metadata_jsonb,
last_metadata_conversion = now()
)
select @simplehash_nft_id::text
Expand Down
5 changes: 3 additions & 2 deletions kafka-streamer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ func parseTokenMessage(ctx context.Context, deserializer *avro.GenericDeserializ
return mirrordb.ProcessEthereumTokenEntryParams{}, err
}

extraMetadata, err := toJSONB(nft.Extra_metadata)
extraMetadataJsonb, err := toJSONB(nft.Extra_metadata)
if err != nil {
err = fmt.Errorf("failed to convert Extra_metadata to JSONB: %w", err)
return mirrordb.ProcessEthereumTokenEntryParams{}, err
Expand Down Expand Up @@ -774,7 +774,8 @@ func parseTokenMessage(ctx context.Context, deserializer *avro.GenericDeserializ
LastSale: lastSale,
FirstCreated: firstCreated,
Rarity: rarity,
ExtraMetadata: extraMetadata,
ExtraMetadata: cleanString(nft.Extra_metadata),
ExtraMetadataJsonb: extraMetadataJsonb,
ImageProperties: imageProperties,
VideoProperties: videoProperties,
AudioProperties: audioProperties,
Expand Down

0 comments on commit 37297fb

Please sign in to comment.