diff --git a/rust/processor/src/db/common/models/token_v2_models/v2_collections.rs b/rust/processor/src/db/common/models/token_v2_models/v2_collections.rs index 5d3a394a9..75cce2cd3 100644 --- a/rust/processor/src/db/common/models/token_v2_models/v2_collections.rs +++ b/rust/processor/src/db/common/models/token_v2_models/v2_collections.rs @@ -47,6 +47,7 @@ pub struct CollectionV2 { pub mutable_description: Option, pub mutable_uri: Option, pub table_handle_v1: Option, + pub collection_properties: Option, pub token_standard: String, pub transaction_timestamp: chrono::NaiveDateTime, } @@ -67,6 +68,7 @@ pub struct CurrentCollectionV2 { pub mutable_uri: Option, pub table_handle_v1: Option, pub token_standard: String, + pub collection_properties: Option, pub last_transaction_version: i64, pub last_transaction_timestamp: chrono::NaiveDateTime, } @@ -104,6 +106,7 @@ impl CollectionV2 { let (mut current_supply, mut max_supply, mut total_minted_v2) = (BigDecimal::zero(), None, None); let (mut mutable_description, mut mutable_uri) = (None, None); + let mut collection_properties = serde_json::Value::Null; if let Some(object_data) = object_metadatas.get(&resource.address) { // Getting supply data (prefer fixed supply over unlimited supply although they should never appear at the same time anyway) let fixed_supply = object_data.fixed_supply.as_ref(); @@ -143,6 +146,12 @@ impl CollectionV2 { mutable_description = Some(collection.mutable_description); mutable_uri = Some(collection.mutable_uri); } + + collection_properties = object_data + .property_map + .as_ref() + .map(|m| m.inner.clone()) + .unwrap_or(collection_properties); } else { // ObjectCore should not be missing, returning from entire function early return Ok(None); @@ -169,6 +178,7 @@ impl CollectionV2 { mutable_description, mutable_uri, table_handle_v1: None, + collection_properties: Some(collection_properties.clone()), token_standard: TokenStandard::V2.to_string(), transaction_timestamp: txn_timestamp, }, @@ -185,6 +195,7 @@ impl CollectionV2 { mutable_uri, table_handle_v1: None, token_standard: TokenStandard::V2.to_string(), + collection_properties: Some(collection_properties), last_transaction_version: txn_version, last_transaction_timestamp: txn_timestamp, }, @@ -282,6 +293,7 @@ impl CollectionV2 { table_handle_v1: Some(table_handle.clone()), token_standard: TokenStandard::V1.to_string(), transaction_timestamp: txn_timestamp, + collection_properties: Some(serde_json::Value::Null), }, CurrentCollectionV2 { collection_id, @@ -296,6 +308,7 @@ impl CollectionV2 { mutable_description: Some(collection_data.mutability_config.description), table_handle_v1: Some(table_handle), token_standard: TokenStandard::V1.to_string(), + collection_properties: Some(serde_json::Value::Null), last_transaction_version: txn_version, last_transaction_timestamp: txn_timestamp, }, diff --git a/rust/processor/src/db/postgres/migrations/2024-07-01-204112_add_collection_properties_to_collections/down.sql b/rust/processor/src/db/postgres/migrations/2024-07-01-204112_add_collection_properties_to_collections/down.sql new file mode 100644 index 000000000..d99a9725f --- /dev/null +++ b/rust/processor/src/db/postgres/migrations/2024-07-01-204112_add_collection_properties_to_collections/down.sql @@ -0,0 +1,5 @@ +ALTER TABLE current_collections_v2 +DROP COLUMN IF EXISTS collection_properties; + +ALTER TABLE collections_v2 +DROP COLUMN IF EXISTS collection_properties; diff --git a/rust/processor/src/db/postgres/migrations/2024-07-01-204112_add_collection_properties_to_collections/up.sql b/rust/processor/src/db/postgres/migrations/2024-07-01-204112_add_collection_properties_to_collections/up.sql new file mode 100644 index 000000000..166f38b4f --- /dev/null +++ b/rust/processor/src/db/postgres/migrations/2024-07-01-204112_add_collection_properties_to_collections/up.sql @@ -0,0 +1,5 @@ +ALTER TABLE current_collections_v2 +ADD COLUMN collection_properties JSONB; + +ALTER TABLE collections_v2 +ADD COLUMN collection_properties JSONB; diff --git a/rust/processor/src/db/postgres/schema.rs b/rust/processor/src/db/postgres/schema.rs index f2e695997..d588329e6 100644 --- a/rust/processor/src/db/postgres/schema.rs +++ b/rust/processor/src/db/postgres/schema.rs @@ -228,6 +228,7 @@ diesel::table! { token_standard -> Varchar, transaction_timestamp -> Timestamp, inserted_at -> Timestamp, + collection_properties -> Nullable, } } @@ -364,6 +365,7 @@ diesel::table! { last_transaction_version -> Int8, last_transaction_timestamp -> Timestamp, inserted_at -> Timestamp, + collection_properties -> Nullable, } } diff --git a/rust/processor/src/processors/token_v2_processor.rs b/rust/processor/src/processors/token_v2_processor.rs index 7008c7059..95645dd8d 100644 --- a/rust/processor/src/processors/token_v2_processor.rs +++ b/rust/processor/src/processors/token_v2_processor.rs @@ -278,7 +278,11 @@ fn insert_collections_v2_query( diesel::insert_into(schema::collections_v2::table) .values(items_to_insert) .on_conflict((transaction_version, write_set_change_index)) - .do_nothing(), + .do_update() + .set(( + collection_properties.eq(excluded(collection_properties)), + inserted_at.eq(excluded(inserted_at)), + )), None, ) } @@ -354,6 +358,7 @@ fn insert_current_collections_v2_query( table_handle_v1.eq(excluded(table_handle_v1)), token_standard.eq(excluded(token_standard)), last_transaction_version.eq(excluded(last_transaction_version)), + collection_properties.eq(excluded(collection_properties)), last_transaction_timestamp.eq(excluded(last_transaction_timestamp)), inserted_at.eq(excluded(inserted_at)), )),