pub(crate) fn create_schema(&self, schema: &SubgraphSchema) -> Result<(), StoreError> {
        use self::public::DeploymentSchemaVersion as v;

        assert_eq!(
            &*SUBGRAPHS_ID,
            self.storage.subgraph(),
            "create_schema can only be called on a Connection for the metadata subgraph"
        );

        // Check if there already is an entry for this subgraph. If so, do
        // nothing
        let count = deployment_schemas::table
            .filter(deployment_schemas::subgraph.eq(schema.id.to_string()))
            .count()
            .first::<i64>(&self.conn)?;
        if count > 0 {
            return Ok(());
        }

        // Create a schema for the deployment.
        let schemas: Vec<String> = diesel::insert_into(deployment_schemas::table)
            .values((
                deployment_schemas::subgraph.eq(schema.id.to_string()),
                deployment_schemas::version.eq(*GRAPH_STORAGE_SCHEME),
            ))
            .returning(deployment_schemas::name)
            .get_results(&self.conn)?;
        let schema_name = schemas
            .first()
            .ok_or_else(|| format_err!("failed to read schema name for {} back", &schema.id))?;

        let query = format!("create schema {}", schema_name);
        self.conn.batch_execute(&*query)?;

        match *GRAPH_STORAGE_SCHEME {
            v::Relational => Layout::create_relational_schema(
                &self.conn,
                &schema_name,
                schema.id.clone(),
                &schema.document,
            )
            .map(|_| ()),
            v::Split => create_split_schema(&self.conn, &schema_name),
        }
    }
/// Create the database schema for a new subgraph, including all tables etc.
///
/// It is an error if `deployment_schemas` already has an entry for this
/// `subgraph_id`. Note that `self` must be a connection for the subgraph
/// of subgraphs
Create the database schema for a new subgraph, including all tables etc.
It is an error if `deployment_schemas` already has an entry for this
`subgraph_id`. Note that `self` must be a connection for the subgraph
of subgraphs
Create the database schema for a new subgraph including all tables etc . It is an error if ` deployment_schemas ` already has an entry for this ` subgraph_id ` . Note that ` self ` must be a connection for the subgraph of subgraphs
pub(crate) fn create_schema(&self, schema: &SubgraphSchema) -> Result<(), StoreError> {
        use self::public::DeploymentSchemaVersion as v;
        assert_eq!(
            &*SUBGRAPHS_ID,
            self.storage.subgraph(),
            "create_schema can only be called on a Connection for the metadata subgraph"
        );
        // Check if there already is an entry for this subgraph. If so, do
        // nothing
        let count = deployment_schemas::table
            .filter(deployment_schemas::subgraph.eq(schema.id.to_string()))
            .count()
            .first::<i64>(&self.conn)?;
        if count > 0 {
            return Ok(());
        }
        // Create a schema for the deployment.
        let schemas: Vec<String> = diesel::insert_into(deployment_schemas::table)
            .values((
                deployment_schemas::subgraph.eq(schema.id.to_string()),
                deployment_schemas::version.eq(*GRAPH_STORAGE_SCHEME),
            ))
            .returning(deployment_schemas::name)
            .get_results(&self.conn)?;
        let schema_name = schemas
            .first()
            .ok_or_else(|| format_err!("failed to read schema name for {} back", &schema.id))?;
        let query = format!("create schema {}", schema_name);
        self.conn.batch_execute(&*query)?;
        match *GRAPH_STORAGE_SCHEME {
            v::Relational => Layout::create_relational_schema(
                &self.conn,
                &schema_name,
                schema.id.clone(),
                &schema.document,
            )
            .map(|_| ()),
            v::Split => create_split_schema(&self.conn, &schema_name),
        }
    }
pub ( crate ) fn create_schema ( & self , schema : & SubgraphSchema ) -> Result < ( ) , StoreError > { use self :: public :: DeploymentSchemaVersion as v ; assert_eq ! ( SUBGRAPHS_ID self storage subgraph ( ) " " ) ; // Check if there already is an entry for this subgraph. If so, do // nothing let count = deployment_schemas :: table . filter ( deployment_schemas :: subgraph . eq ( schema . id . to_string ( ) ) ) . count ( ) . first :: < i64 > ( & self . conn ) ? ; if count > 0 { return Ok ( ( ) ) ; } // Create a schema for the deployment. let schemas : Vec < String > = diesel :: insert_into ( deployment_schemas :: table ) . values ( ( deployment_schemas :: subgraph . eq ( schema . id . to_string ( ) ) , deployment_schemas :: version . eq ( * GRAPH_STORAGE_SCHEME ) , ) ) . returning ( deployment_schemas :: name ) . get_results ( & self . conn ) ? ; let schema_name = schemas . first ( ) . ok_or_else ( | | format_err ! ( " " schema id ) ) ? ; let query = format ! ( " " schema_name ) ; self . conn . batch_execute ( & * query ) ? ; match * GRAPH_STORAGE_SCHEME { v :: Relational => Layout :: create_relational_schema ( & self . conn , & schema_name , schema . id . clone ( ) , & schema . document , ) . map ( | _ | ( ) ) , v :: Split => create_split_schema ( & self . conn , & schema_name ) , } }
Create the database schema for a new subgraph, including all tables etc.
Create the database schema for a new subgraph including all tables etc .
&self
schema
&SubgraphSchema
&self
schema
&SubgraphSchema