Skip to content

Commit d8bea9d

Browse files
author
Zoran Cvetkov
committed
fix spec version in input schema
1 parent ec452e8 commit d8bea9d

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

graph/src/components/store/entity_cache.rs

Lines changed: 22 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

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

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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,8 @@ impl Table {
115115

116116
Ok(cols)
117117
}
118-
119-
let vid_type = if !self.object.is_object_type() {
120-
"bigserial"
121-
} else {
122-
"bigint"
123-
};
118+
let new_vid_form = self.object.new_vid_form() && self.object.is_object_type();
119+
let vid_type = if new_vid_form { "bigint" } else { "bigserial" };
124120

125121
if self.immutable {
126122
writeln!(

0 commit comments

Comments
 (0)