Skip to content

Commit

Permalink
fix spec version in input schema
Browse files Browse the repository at this point in the history
  • Loading branch information
zorancv committed Jan 28, 2025
1 parent ec452e8 commit d8bea9d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
24 changes: 22 additions & 2 deletions graph/src/components/store/entity_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,13 @@ impl EntityCache {
};

// Always test the cache consistency in debug mode. The test only
// makes sense when we were actually asked to read from the store
// makes sense when we were actually asked to read from the store.
// We need to remove the VID as the one from the DB might come from
// a legacy subgraph that has VID autoincremented while this trait
// always creates it in a new style.
debug_assert!(match scope {
GetScope::Store => entity == self.store.get(key).unwrap().map(Arc::new),
GetScope::Store =>
remove_vid(entity.clone()) == remove_vid(self.store.get(key).unwrap().map(Arc::new)),
GetScope::InBlock => true,
});

Expand Down Expand Up @@ -547,3 +551,19 @@ impl EntityCache {
})
}
}

// Release build still needs this function althought it will never call it
#[cfg(not(debug_assertions))]
fn remove_vid(_: Option<Arc<Entity>>) -> Option<Entity> {
None
}

#[cfg(debug_assertions)]
fn remove_vid(entity: Option<Arc<Entity>>) -> Option<Entity> {
entity.map(|e| {
let mut entity = (*e).clone();
#[cfg(debug_assertions)]
entity.remove_vid();
entity
})
}
11 changes: 7 additions & 4 deletions store/postgres/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use diesel::{
sql_query,
sql_types::{Nullable, Text},
};
use graph::semver::Version;
use graph::{
blockchain::block_stream::FirehoseCursor, data::subgraph::schema::SubgraphError, env::ENV_VARS,
schema::EntityType,
Expand Down Expand Up @@ -301,11 +302,13 @@ pub fn debug_fork(

pub fn schema(conn: &mut PgConnection, site: &Site) -> Result<(InputSchema, bool), StoreError> {
use subgraph_manifest as sm;
let (s, use_bytea_prefix) = sm::table
.select((sm::schema, sm::use_bytea_prefix))
let (s, spec_ver, use_bytea_prefix) = sm::table
.select((sm::schema, sm::spec_version, sm::use_bytea_prefix))
.filter(sm::id.eq(site.id))
.first::<(String, bool)>(conn)?;
InputSchema::parse_latest(s.as_str(), site.deployment.clone())
.first::<(String, String, bool)>(conn)?;
let spec_version =
Version::parse(spec_ver.as_str()).map_err(|err| StoreError::Unknown(err.into()))?;
InputSchema::parse(&spec_version, s.as_str(), site.deployment.clone())
.map_err(StoreError::Unknown)
.map(|schema| (schema, use_bytea_prefix))
}
Expand Down
8 changes: 2 additions & 6 deletions store/postgres/src/relational/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,8 @@ impl Table {

Ok(cols)
}

let vid_type = if !self.object.is_object_type() {
"bigserial"
} else {
"bigint"
};
let new_vid_form = self.object.new_vid_form() && self.object.is_object_type();
let vid_type = if new_vid_form { "bigint" } else { "bigserial" };

if self.immutable {
writeln!(
Expand Down

0 comments on commit d8bea9d

Please sign in to comment.