Skip to content

Commit

Permalink
store: prepare for breaking changes of the database
Browse files Browse the repository at this point in the history
  • Loading branch information
zorancv committed Jan 10, 2025
1 parent fea46ab commit 9fdfdca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion node/src/store_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
16 changes: 16 additions & 0 deletions store/postgres/src/block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(())
}

Expand Down

0 comments on commit 9fdfdca

Please sign in to comment.