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 2 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: 13 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,18 @@

// 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") {
return Ok(());
}
return Err(e);
}
};

Check warning on line 70 in crates/torii/core/src/processors/upgrade_event.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/processors/upgrade_event.rs#L59-L70

Added lines #L59 - L70 were not covered by tests
Larkooo marked this conversation as resolved.
Show resolved Hide resolved
let name = model.name;
let namespace = model.namespace;
let prev_schema = model.schema;
Expand Down
15 changes: 13 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,18 @@
}
};

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") {
return Ok(());
}
return Err(e);
}
};

Check warning on line 68 in crates/torii/core/src/processors/upgrade_model.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/processors/upgrade_model.rs#L57-L68

Added lines #L57 - L68 were not covered by tests
let name = model.name;
let namespace = model.namespace;
let prev_schema = model.schema;
Expand Down
Loading