diff --git a/node/src/store_builder.rs b/node/src/store_builder.rs index 2a39d0ea6ed..7fadf6b92c2 100644 --- a/node/src/store_builder.rs +++ b/node/src/store_builder.rs @@ -191,7 +191,7 @@ impl StoreBuilder { ); block_store .update_db_version() - .expect("Updating `db_version` works"); + .expect("Updating `db_version` should work"); Arc::new(DieselStore::new(subgraph_store, block_store)) } diff --git a/store/postgres/src/block_store.rs b/store/postgres/src/block_store.rs index efaca838d59..9af40b8d2a0 100644 --- a/store/postgres/src/block_store.rs +++ b/store/postgres/src/block_store.rs @@ -33,6 +33,10 @@ use self::primary::Chain; #[cfg(debug_assertions)] pub const FAKE_NETWORK_SHARED: &str = "fake_network_shared"; +// Highest version of the database that the executable supports. +// To be incremented on each breaking change to the database. +const SUPPORTED_DB_VERSION: i64 = 3; + /// The status of a chain: whether we can only read from the chain, or /// whether it is ok to ingest from it, too #[derive(Copy, Clone)] @@ -531,6 +535,18 @@ impl BlockStore { .set(dbv::version.eq(3)) .execute(&mut conn)?; }; + if version < SUPPORTED_DB_VERSION { + // Bump it to make sure that all executables are working with the same DB format + diesel::update(dbv::table) + .set(dbv::version.eq(SUPPORTED_DB_VERSION)) + .execute(&mut conn)?; + }; + if version > SUPPORTED_DB_VERSION { + panic!( + "The executable is too old and doesn't support the database version: {}", + version + ) + } Ok(()) }