Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(torii-core): upgrade model silent if not in namespace #2688

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions crates/torii/core/src/processors/store_del_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dojo_world::contracts::abigen::world::Event as WorldEvent;
use dojo_world::contracts::world::WorldContractReader;
use starknet::core::types::Event;
use starknet::providers::Provider;
use tracing::info;
use tracing::{debug, info};

use super::{EventProcessor, EventProcessorConfig};
use crate::sql::Sql;
Expand Down Expand Up @@ -55,12 +55,15 @@ where
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) => {
if e.to_string().contains("no rows") {
return Ok(());
}
return Err(e);
Err(e) if e.to_string().contains("no rows") => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
};

info!(
Expand Down
15 changes: 9 additions & 6 deletions crates/torii/core/src/processors/store_set_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dojo_world::contracts::abigen::world::Event as WorldEvent;
use dojo_world::contracts::world::WorldContractReader;
use starknet::core::types::Event;
use starknet::providers::Provider;
use tracing::info;
use tracing::{debug, info};

use super::{EventProcessor, EventProcessorConfig};
use crate::sql::utils::felts_to_sql_string;
Expand Down Expand Up @@ -56,12 +56,15 @@ where
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) => {
if e.to_string().contains("no rows") {
return Ok(());
}
return Err(e);
Err(e) if e.to_string().contains("no rows") => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
};

info!(
Expand Down
15 changes: 9 additions & 6 deletions crates/torii/core/src/processors/store_update_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dojo_world::contracts::abigen::world::Event as WorldEvent;
use dojo_world::contracts::world::WorldContractReader;
use starknet::core::types::Event;
use starknet::providers::Provider;
use tracing::info;
use tracing::{debug, info};

use super::{EventProcessor, EventProcessorConfig};
use crate::sql::Sql;
Expand Down Expand Up @@ -59,12 +59,15 @@ where
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) => {
if e.to_string().contains("no rows") {
return Ok(());
}
return Err(e);
Err(e) if e.to_string().contains("no rows") => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
};

info!(
Expand Down
18 changes: 16 additions & 2 deletions crates/torii/core/src/processors/upgrade_event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{Error, Ok, Result};
use anyhow::{Error, Result};
use async_trait::async_trait;
use dojo_world::contracts::abigen::world::Event as WorldEvent;
use dojo_world::contracts::model::ModelReader;
Expand Down Expand Up @@ -56,7 +56,21 @@ where

// Called model here by language, but it's an event. Torii rework will make clear
// distinction.
let model = db.model(event.selector).await?;

// If the model does not exist, silently ignore it.
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) if e.to_string().contains("no rows") => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
};
let name = model.name;
let namespace = model.namespace;
let prev_schema = model.schema;
Expand Down
18 changes: 16 additions & 2 deletions crates/torii/core/src/processors/upgrade_model.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{Error, Ok, Result};
use anyhow::{Error, Result};
use async_trait::async_trait;
use dojo_world::contracts::abigen::world::Event as WorldEvent;
use dojo_world::contracts::model::ModelReader;
Expand Down Expand Up @@ -54,7 +54,21 @@ where
}
};

let model = db.model(event.selector).await?;
// If the model does not exist, silently ignore it.
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) if e.to_string().contains("no rows") => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
};

let name = model.name;
let namespace = model.namespace;
let prev_schema = model.schema;
Expand Down
Loading