Skip to content

Commit 9fdfdca

Browse files
Zoran Cvetkovzorancv
authored andcommitted
store: prepare for breaking changes of the database
1 parent fea46ab commit 9fdfdca

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

node/src/store_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl StoreBuilder {
191191
);
192192
block_store
193193
.update_db_version()
194-
.expect("Updating `db_version` works");
194+
.expect("Updating `db_version` should work");
195195

196196
Arc::new(DieselStore::new(subgraph_store, block_store))
197197
}

store/postgres/src/block_store.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ use self::primary::Chain;
3333
#[cfg(debug_assertions)]
3434
pub const FAKE_NETWORK_SHARED: &str = "fake_network_shared";
3535

36+
// Highest version of the database that the executable supports.
37+
// To be incremented on each breaking change to the database.
38+
const SUPPORTED_DB_VERSION: i64 = 3;
39+
3640
/// The status of a chain: whether we can only read from the chain, or
3741
/// whether it is ok to ingest from it, too
3842
#[derive(Copy, Clone)]
@@ -531,6 +535,18 @@ impl BlockStore {
531535
.set(dbv::version.eq(3))
532536
.execute(&mut conn)?;
533537
};
538+
if version < SUPPORTED_DB_VERSION {
539+
// Bump it to make sure that all executables are working with the same DB format
540+
diesel::update(dbv::table)
541+
.set(dbv::version.eq(SUPPORTED_DB_VERSION))
542+
.execute(&mut conn)?;
543+
};
544+
if version > SUPPORTED_DB_VERSION {
545+
panic!(
546+
"The executable is too old and doesn't support the database version: {}",
547+
version
548+
)
549+
}
534550
Ok(())
535551
}
536552

0 commit comments

Comments
 (0)