Skip to content

Commit 0a0034c

Browse files
committed
store: Validate subgraph name exists before restore
When --name is passed to `graphman restore`, check that the subgraph actually exists in the database before creating the deployment. Without this check, the deployment would be created but never linked to a name, leaving it orphaned and hard to clean up.
1 parent 95adf51 commit 0a0034c

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

store/postgres/src/subgraph_store.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,14 +1465,25 @@ impl Inner {
14651465
// Resolve the subgraph name for deployment rule matching. If not
14661466
// supplied, look up an existing name from the DB; error if none.
14671467
let name = match name {
1468-
Some(n) => n,
1468+
Some(name) => {
1469+
// Validate that the named subgraph exists. Without this
1470+
// check the deployment would be created but never linked
1471+
// to a name, leaving it orphaned.
1472+
if !self.mirror.subgraph_exists(&name).await? {
1473+
return Err(StoreError::Input(format!(
1474+
"subgraph `{name}` does not exist; \
1475+
create it first with `graphman create {name}`"
1476+
)));
1477+
}
1478+
name
1479+
}
14691480
None => {
14701481
let names = self
14711482
.mirror
14721483
.subgraphs_by_deployment_hash(metadata.deployment.as_str())
14731484
.await?;
14741485
let (name, _) = names.into_iter().next().ok_or_else(|| {
1475-
StoreError::InternalError(
1486+
StoreError::Input(
14761487
"no subgraph name found for this deployment; use --name to specify one"
14771488
.into(),
14781489
)

0 commit comments

Comments
 (0)