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

Function remove_nonempty_table_fails

crates/engine/src/update.rs:935–966  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

933
934 #[test]
935 fn remove_nonempty_table_fails() -> anyhow::Result<()> {
936 let auth_ctx = AuthCtx::for_testing();
937 let stdb = TestDB::durable()?;
938
939 let old = single_table_module();
940 let new = empty_module();
941
942 let mut tx = begin_mut_tx(&stdb);
943 for def in old.tables() {
944 create_table_from_def(&stdb, &mut tx, &old, def)?;
945 }
946 let table_id = stdb
947 .table_id_from_name_mut(&tx, "droppable")?
948 .expect("table should exist");
949 insert(&stdb, &mut tx, table_id, &product![42u64])?;
950 stdb.commit_tx(tx)?;
951
952 let mut tx = begin_mut_tx(&stdb);
953 let plan = ponder_migrate(&old, &new)?;
954 let result = update_database(&stdb, &mut tx, auth_ctx, plan, &TestLogger);
955 let err = result.err().expect("removing a non-empty table should fail");
956 assert!(
957 err.to_string().contains("table contains data"),
958 "error should mention that the table contains data, got: {err}"
959 );
960 assert!(
961 tx.pending_schema_changes().is_empty(),
962 "failed migration should leave no pending schema changes: {:?}",
963 tx.pending_schema_changes()
964 );
965 Ok(())
966 }
967
968 /// Verifies that `autoinc` sequence survives a schema migration that adds a column,
969 /// and is also correctly persisted across database replay.

Callers

nothing calls this directly

Calls 12

single_table_moduleFunction · 0.85
empty_moduleFunction · 0.85
create_table_from_defFunction · 0.85
ponder_migrateFunction · 0.85
update_databaseFunction · 0.85
commit_txMethod · 0.80
errMethod · 0.80
begin_mut_txFunction · 0.70
insertFunction · 0.70
OkFunction · 0.50
tablesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…