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

Function update_database

crates/engine/src/update.rs:127–153  ·  view source on GitHub ↗

Update the database according to the migration plan. The update is performed within the transactional context `tx`. NOTE: Manual migration support is predicated on the transactionality of dropping database objects (tables, indexes, etc.). Currently, none of the drop_* methods are transactional. This is safe because the __update__ reducer is no longer supported, and the auto plan guarantees that t

(
    stdb: &RelationalDB,
    tx: &mut MutTxId,
    auth_ctx: AuthCtx,
    plan: MigratePlan,
    logger: &dyn UpdateLogger,
)

Source from the content-addressed store, hash-verified

125// But when implementing manual migrations, we need to make sure that
126// drop_* become transactional.
127pub fn update_database(
128 stdb: &RelationalDB,
129 tx: &mut MutTxId,
130 auth_ctx: AuthCtx,
131 plan: MigratePlan,
132 logger: &dyn UpdateLogger,
133) -> anyhow::Result<UpdateResult> {
134 let existing_tables = stdb.get_all_tables_mut(tx)?;
135
136 // TODO: consider using `ErrorStream` here.
137 let old_module_def = plan.old_def();
138 for table in existing_tables
139 .iter()
140 .filter(|table| table.table_type != StTableType::System && !table.is_view())
141 {
142 let old_def = old_module_def
143 .table(&table.table_name[..])
144 .ok_or_else(|| anyhow::anyhow!("table {} not found in old_module_def", table.table_name))?;
145
146 table.check_compatible(old_module_def, old_def)?;
147 }
148
149 match plan {
150 MigratePlan::Manual(plan) => manual_migrate_database(stdb, tx, plan, logger),
151 MigratePlan::Auto(plan) => auto_migrate_database(stdb, tx, auth_ctx, plan, logger),
152 }
153}
154
155/// Manually migrate a database.
156fn manual_migrate_database(

Calls 9

manual_migrate_databaseFunction · 0.85
auto_migrate_databaseFunction · 0.85
get_all_tables_mutMethod · 0.80
old_defMethod · 0.80
check_compatibleMethod · 0.80
filterMethod · 0.65
iterMethod · 0.65
is_viewMethod · 0.45
tableMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…