{"record":{"id":"c894652d46596574","repo":"clockworklabs/SpacetimeDB","slug":"addindex-index-index-name-not-found-in-new-mo","errorCode":null,"errorMessage":"AddIndex: index `{index_name}` not found in new module def","messagePattern":"AddIndex: index `(.+?)` not found in new module def","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":327,"sourceCode":"            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::UpdateView(_) => {\n                // if we already have to disconnect clients, no need to set\n                // `EvaluateSubscribedViews` as clients will be disconnected anyway\n                if !matches!(res, UpdateResult::RequiresClientDisconnect) {\n                    res = UpdateResult::EvaluateSubscribedViews;\n                }\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::AddIndex(key) => {\n                let (namespace, index_name) = key;\n                let (owning_def, table_def) = plan\n                    .new\n                    .find_storing_table(namespace, index_name)\n                    .ok_or_else(|| anyhow::anyhow!(\"AddIndex: `{index_name}` not found in new module def\"))?;\n                let table_full_name = joined(namespace, &table_def.name);\n                let index_def: &IndexDef = plan\n                    .new\n                    .lookup(key)\n                    .ok_or_else(|| anyhow::anyhow!(\"AddIndex: index `{index_name}` not found in new module def\"))?;\n                let table_id = stdb.table_id_from_name_mut(tx, &table_full_name)?.unwrap();\n\n                let index_cols = ColSet::from(index_def.algorithm.columns());\n\n                let is_unique = table_def\n                    .constraints\n                    .iter()\n                    .filter_map(|(_, c)| c.data.unique_columns())\n                    .any(|unique_cols| unique_cols == &index_cols);\n\n                log!(logger, \"Creating index `{index_name}` on table `{table_full_name}`\");\n\n                let mut index_schema = IndexSchema::from_module_def(owning_def, index_def, table_id, 0.into());\n\n                // Apply namespace prefix for submodule indexes\n                index_schema.index_name = namespace.join_raw(&index_schema.index_name);\n                index_schema.alias = index_schema.alias.as_ref().map(|alias| namespace.join_raw(alias));\n","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L309-L345","documentation":"Auto-migrate step AddIndex: the storing table was found, but plan.new.lookup(key) returned None for the IndexDef itself. The index key resolves to a table yet the def's index map has no entry — plan and def disagree, an internal invariant break.","triggerScenarios":"A def revision where the index was removed after the step list was computed; hand-assembled plans mixing key sets and def maps; differ bug leaving the storing-table edge without the index definition.","commonSituations":"Manual plan construction; schema crate version skew; tests mutating defs between diff and apply.","solutions":["Rebuild plan and plan.new from a single consistent ModuleDef","Never mix keys from one def with lookups into another","Report upstream with the key if machine-generated"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match auto_migrate_database(&stdb, &mut tx, auth, &plan, &logger) {\n    Err(e) if e.to_string().contains(\"index\") && e.to_string().contains(\"not found in new module def\") => {\n        // storing table resolved but IndexDef missing: rebuild plan from a single def, retry once\n        let plan2 = MigratePlan::Auto(diff_defs(old_def, new_def)?);\n        auto_migrate_database(&stdb, &mut tx, auth, &plan2, &logger)\n    }\n    r => r,\n}","preventionTips":["Never mix keys from one def with lookup maps of another","Do not edit defs between plan computation and application","File upstream bugs with the failing (namespace, index) key"],"tags":["rust","spacetimedb","migration","index","internal-invariant"],"backgroundTag":"migration-plan-invalid","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}