From ef2a492da256205416b28e1e53265037a1031e2d Mon Sep 17 00:00:00 2001 From: Leonardo Yvens Date: Thu, 29 Apr 2021 15:03:40 -0300 Subject: [PATCH] graphman: Add --- node/src/bin/manager.rs | 6 ++++++ node/src/manager/commands/create.rs | 14 ++++++++++++++ node/src/manager/commands/mod.rs | 1 + 3 files changed, 21 insertions(+) create mode 100644 node/src/manager/commands/create.rs diff --git a/node/src/bin/manager.rs b/node/src/bin/manager.rs index 298b4f49b7a..444aa38b7cd 100644 --- a/node/src/bin/manager.rs +++ b/node/src/bin/manager.rs @@ -102,6 +102,11 @@ pub enum Command { /// The name of the subgraph to remove name: String, }, + /// Create a subgraph name + Create { + /// The name of the subgraph to create + name: String, + }, /// Assign or reassign a deployment Reassign { /// The id of the deployment to reassign @@ -453,6 +458,7 @@ async fn main() { } } Remove { name } => commands::remove::run(ctx.subgraph_store(), name), + Create { name } => commands::create::run(ctx.subgraph_store(), name), Unassign { id, shard } => commands::assign::unassign(ctx.subgraph_store(), id, shard), Reassign { id, node, shard } => { commands::assign::reassign(ctx.subgraph_store(), id, node, shard) diff --git a/node/src/manager/commands/create.rs b/node/src/manager/commands/create.rs new file mode 100644 index 00000000000..02e1184684f --- /dev/null +++ b/node/src/manager/commands/create.rs @@ -0,0 +1,14 @@ +use std::sync::Arc; + +use graph::prelude::{anyhow, Error, SubgraphName, SubgraphStore as _}; +use graph_store_postgres::SubgraphStore; + +pub fn run(store: Arc, name: String) -> Result<(), Error> { + let name = SubgraphName::new(name.clone()) + .map_err(|()| anyhow!("illegal subgraph name `{}`", name))?; + + println!("creating subgraph {}", name); + store.create_subgraph(name)?; + + Ok(()) +} diff --git a/node/src/manager/commands/mod.rs b/node/src/manager/commands/mod.rs index 0c991153e2f..1b0002f00a4 100644 --- a/node/src/manager/commands/mod.rs +++ b/node/src/manager/commands/mod.rs @@ -1,6 +1,7 @@ pub mod assign; pub mod config; pub mod copy; +pub mod create; pub mod info; pub mod listen; pub mod query;