Skip to content

Commit

Permalink
store: use DeploymentFeatures struct in create_subgraph_features me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
incrypto32 committed Jun 12, 2023
1 parent de892b1 commit 9ad0974
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
19 changes: 6 additions & 13 deletions store/postgres/src/primary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,23 +1140,16 @@ impl<'a> Connection<'a> {
Ok(features)
}

pub fn create_subgraph_features(
&self,
id: String,
spec_version: String,
features: Vec<String>,
api_version: Option<String>,
data_source_kinds: Vec<String>,
) -> Result<(), StoreError> {
pub fn create_subgraph_features(&self, features: DeploymentFeatures) -> Result<(), StoreError> {
use subgraph_features as f;

let conn = self.conn.as_ref();
let changes = (
f::id.eq(id),
f::spec_version.eq(spec_version),
f::api_version.eq(api_version),
f::features.eq(features),
f::data_sources.eq(data_source_kinds),
f::id.eq(features.id),
f::spec_version.eq(features.spec_version),
f::api_version.eq(features.api_version),
f::features.eq(features.features),
f::data_sources.eq(features.data_source_kinds),
);

insert_into(f::table)
Expand Down
9 changes: 1 addition & 8 deletions store/postgres/src/subgraph_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,19 +572,12 @@ impl SubgraphStoreInner {
// FIXME: This simultaneously holds a `primary_conn` and a shard connection, which can
// potentially deadlock.
let pconn = self.primary_conn()?;

pconn.transaction(|| -> Result<_, StoreError> {
// Create subgraph, subgraph version, and assignment
let changes =
pconn.create_subgraph_version(name, &site, node_id, mode, exists_and_synced)?;

pconn.create_subgraph_features(
features.id.to_string(),
features.spec_version,
features.features,
features.api_version,
features.data_source_kinds,
)?;
pconn.create_subgraph_features(features)?;

let event = StoreEvent::new(changes);
pconn.send_store_event(&self.sender, &event)?;
Expand Down
2 changes: 2 additions & 0 deletions store/test-store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub async fn create_subgraph(
base: Option<(DeploymentHash, BlockPtr)>,
) -> Result<DeploymentLocator, StoreError> {
let schema = InputSchema::parse(schema, subgraph_id.clone()).unwrap();

let manifest = SubgraphManifest::<graph::blockchain::mock::MockBlockchain> {
id: subgraph_id.clone(),
spec_version: Version::new(1, 0, 0),
Expand Down Expand Up @@ -201,6 +202,7 @@ pub async fn create_subgraph_with_manifest(
.await?;
Ok(deployment)
}

pub async fn create_test_subgraph(subgraph_id: &DeploymentHash, schema: &str) -> DeploymentLocator {
create_subgraph(subgraph_id, schema, None).await.unwrap()
}
Expand Down

0 comments on commit 9ad0974

Please sign in to comment.