1
1
use super :: relational_db:: RelationalDB ;
2
2
use crate :: database_logger:: SystemLogger ;
3
3
use crate :: sql:: parser:: RowLevelExpr ;
4
+ use crate :: subscription:: module_subscription_actor:: ModuleSubscriptions ;
4
5
use spacetimedb_data_structures:: map:: HashMap ;
5
6
use spacetimedb_datastore:: locking_tx_datastore:: MutTxId ;
6
7
use spacetimedb_lib:: db:: auth:: StTableType ;
@@ -35,6 +36,7 @@ impl UpdateLogger for SystemLogger {
35
36
// drop_* become transactional.
36
37
pub fn update_database (
37
38
stdb : & RelationalDB ,
39
+ subscriptions : & ModuleSubscriptions ,
38
40
tx : & mut MutTxId ,
39
41
auth_ctx : AuthCtx ,
40
42
plan : MigratePlan ,
@@ -57,7 +59,9 @@ pub fn update_database(
57
59
58
60
match plan {
59
61
MigratePlan :: Manual ( plan) => manual_migrate_database ( stdb, tx, plan, logger, existing_tables) ,
60
- MigratePlan :: Auto ( plan) => auto_migrate_database ( stdb, tx, auth_ctx, plan, logger, existing_tables) ,
62
+ MigratePlan :: Auto ( plan) => {
63
+ auto_migrate_database ( stdb, subscriptions, tx, auth_ctx, plan, logger, existing_tables)
64
+ }
61
65
}
62
66
}
63
67
@@ -83,6 +87,7 @@ macro_rules! log {
83
87
/// Automatically migrate a database.
84
88
fn auto_migrate_database (
85
89
stdb : & RelationalDB ,
90
+ subscriptions : & ModuleSubscriptions ,
86
91
tx : & mut MutTxId ,
87
92
auth_ctx : AuthCtx ,
88
93
plan : AutoMigratePlan ,
@@ -264,7 +269,12 @@ fn auto_migrate_database(
264
269
. collect ( ) ;
265
270
stdb. add_columns_to_table ( tx, table_id, column_schemas, default_values) ?;
266
271
}
267
- _ => anyhow:: bail!( "migration step not implemented: {step:?}" ) ,
272
+ spacetimedb_schema:: auto_migrate:: AutoMigrateStep :: DisconnectAllUsers => {
273
+ // Disconnect all clients from subscriptions.
274
+ // Any dangling clients will be handled during the launch of module hosts,
275
+ // which invokes `ModuleHost::call_identity_disconnected`.
276
+ subscriptions. remove_all_subscribers ( ) ;
277
+ }
268
278
}
269
279
}
270
280
@@ -349,7 +359,14 @@ mod test {
349
359
// Try to update the db.
350
360
let mut tx = begin_mut_tx ( & stdb) ;
351
361
let plan = ponder_migrate ( & old, & new) ?;
352
- update_database ( & stdb, & mut tx, auth_ctx, plan, & TestLogger ) ?;
362
+ update_database (
363
+ & stdb,
364
+ & ModuleSubscriptions :: for_test_new_runtime ( Arc :: new ( stdb. db . clone ( ) ) ) . 0 ,
365
+ & mut tx,
366
+ auth_ctx,
367
+ plan,
368
+ & TestLogger ,
369
+ ) ?;
353
370
354
371
// Expect the schema change.
355
372
let idx_b_id = stdb
0 commit comments