MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / update_module

Function update_module

crates/core/src/host/host_controller.rs:845–867  ·  view source on GitHub ↗

Update a module. If the `db` is not initialized yet (i.e. its program hash is `None`), return an error. Otherwise, if `db.program_hash` matches the given `program_hash`, do nothing and return an empty `UpdateDatabaseResult`. Otherwise, invoke `module.update_database` and return the result.

(
    db: &RelationalDB,
    module: &ModuleHost,
    program: Program,
    old_module_info: Arc<ModuleInfo>,
    policy: MigrationPolicy,
)

Source from the content-addressed store, hash-verified

843///
844/// Otherwise, invoke `module.update_database` and return the result.
845async fn update_module(
846 db: &RelationalDB,
847 module: &ModuleHost,
848 program: Program,
849 old_module_info: Arc<ModuleInfo>,
850 policy: MigrationPolicy,
851) -> anyhow::Result<UpdateDatabaseResult> {
852 let addr = db.database_identity();
853 match stored_program_hash(db)? {
854 None => Err(anyhow!("database `{addr}` not yet initialized")),
855 Some(stored) => {
856 let res = if stored == program.hash {
857 info!("database `{}` up to date with program `{}`", addr, program.hash);
858 UpdateDatabaseResult::NoUpdateNeeded
859 } else {
860 info!("updating `{}` from {} to {}", addr, stored, program.hash);
861 module.update_database(program, old_module_info, policy).await?
862 };
863
864 Ok(res)
865 }
866 }
867}
868
869/// Encapsulates a database, associated module, and auxiliary state.
870struct Host {

Callers 1

update_moduleMethod · 0.85

Calls 5

stored_program_hashFunction · 0.85
ErrFunction · 0.50
OkFunction · 0.50
database_identityMethod · 0.45
update_databaseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…