Skip to content

Commit b34bb56

Browse files
author
Zoran Cvetkov
committed
fix spec version in input schema
1 parent ac9f9bc commit b34bb56

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

graph/src/components/store/entity_cache.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,13 @@ impl EntityCache {
207207
};
208208

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

@@ -549,3 +553,18 @@ impl EntityCache {
549553
})
550554
}
551555
}
556+
557+
// Release build still needs this function althought it will never call it
558+
#[cfg(not(debug_assertions))]
559+
fn remove_vid(_: Option<Arc<Entity>>) -> Option<Entity> {
560+
None
561+
}
562+
563+
#[cfg(debug_assertions)]
564+
fn remove_vid(entity: Option<Arc<Entity>>) -> Option<Entity> {
565+
entity.map(|e| {
566+
let mut entity = (*e).clone();
567+
entity.remove("vid");
568+
entity
569+
})
570+
}

store/postgres/src/deployment.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use diesel::{
1313
sql_query,
1414
sql_types::{Nullable, Text},
1515
};
16+
use graph::semver::Version;
1617
use graph::{
1718
blockchain::block_stream::FirehoseCursor, data::subgraph::schema::SubgraphError, env::ENV_VARS,
1819
schema::EntityType,
@@ -301,11 +302,13 @@ pub fn debug_fork(
301302

302303
pub fn schema(conn: &mut PgConnection, site: &Site) -> Result<(InputSchema, bool), StoreError> {
303304
use subgraph_manifest as sm;
304-
let (s, use_bytea_prefix) = sm::table
305-
.select((sm::schema, sm::use_bytea_prefix))
305+
let (s, spec_ver, use_bytea_prefix) = sm::table
306+
.select((sm::schema, sm::spec_version, sm::use_bytea_prefix))
306307
.filter(sm::id.eq(site.id))
307-
.first::<(String, bool)>(conn)?;
308-
InputSchema::parse_latest(s.as_str(), site.deployment.clone())
308+
.first::<(String, String, bool)>(conn)?;
309+
let spec_version =
310+
Version::parse(spec_ver.as_str()).map_err(|err| StoreError::Unknown(err.into()))?;
311+
InputSchema::parse(&spec_version, s.as_str(), site.deployment.clone())
309312
.map_err(StoreError::Unknown)
310313
.map(|schema| (schema, use_bytea_prefix))
311314
}

store/postgres/src/relational/ddl.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,8 @@ impl Table {
117117
}
118118

119119
// Currently the agregations entities don't have VIDs in insertion order
120-
let vid_type = if self.object.is_object_type() {
121-
"bigint"
122-
} else {
123-
"bigserial"
124-
};
120+
let new_vid_form = self.object.new_vid_form() && self.object.is_object_type();
121+
let vid_type = if new_vid_form { "bigint" } else { "bigserial" };
125122

126123
if self.immutable {
127124
writeln!(

0 commit comments

Comments
 (0)