{"record":{"id":"12312fc338dcf2a3","repo":"clockworklabs/SpacetimeDB","slug":"changeindexsourcename-index-name-not-found-in","errorCode":null,"errorMessage":"ChangeIndexSourceName: `{index_name}` not found in old module def","messagePattern":"ChangeIndexSourceName: `(.+?)` not found in old module def","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":419,"sourceCode":"                    .columns\n                    .iter()\n                    .find(|col| &col.col_name == col_name)\n                    .ok_or_else(|| anyhow::anyhow!(\"Column `{col_name}` not found in table `{table_name}`\"))?;\n\n                log!(\n                    logger,\n                    \"Changing column accessor name for `{}`.`{}` to `{}`\",\n                    table_name,\n                    col_name,\n                    new_col_def.accessor_name,\n                );\n                stdb.alter_column_accessor_name(tx, table_id, col_schema.col_pos, new_col_def.accessor_name.clone())?;\n            }\n            spacetimedb_schema::auto_migrate::AutoMigrateStep::ChangeIndexSourceName(key) => {\n                let (namespace, index_name) = key;\n                let (_old_owning_def, old_table_def) =\n                    plan.old.find_storing_table(namespace, index_name).ok_or_else(|| {\n                        anyhow::anyhow!(\"ChangeIndexSourceName: `{index_name}` not found in old module def\")\n                    })?;\n                let (_new_owning_def, new_table_def) =\n                    plan.new.find_storing_table(namespace, index_name).ok_or_else(|| {\n                        anyhow::anyhow!(\"ChangeIndexSourceName: `{index_name}` not found in new module def\")\n                    })?;\n                let table_full_name = joined(namespace, &old_table_def.name);\n                let stored_name = namespace.join_raw(&index_name.clone().into());\n                let new_index_def = new_table_def\n                    .indexes\n                    .get(index_name)\n                    .ok_or_else(|| anyhow::anyhow!(\"Index `{index_name}` not found in table `{table_full_name}`\"))?;\n\n                let table_id = stdb.table_id_from_name_mut(tx, &table_full_name)?.unwrap();\n                let table_schema = stdb.schema_for_table_mut(tx, table_id)?;\n                let index_schema = table_schema\n                    .indexes\n                    .iter()\n                    .find(|index| index.index_name == stored_name)","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L401-L437","documentation":"Applying AutoMigrateStep::ChangeIndexSourceName: the planner decided an index's source name changed (e.g. the column/type accessor feeding the index was renamed), but plan.old.find_storing_table(namespace, index_name) cannot find any table in the old module def that stores this index. The step's key does not resolve in the old defs, so stored and new index metadata cannot be compared. The publish aborts.","triggerScenarios":"Renaming the column or accessor an index is built on while also renaming/dropping the index or its table in one publish; or the old-def reconstruction differs from the schema the live database was published with (auto-generated index names differ across compiler versions).","commonSituations":"Renaming indexed columns together with #[index(...)] edits; republishing databases created by older spacetimedb compilers that auto-named indexes differently; moving indexed tables into submodules.","solutions":["Clean-rebuild and republish (cargo clean, spacetime build, spacetime publish <db>).","Split the change: rename the indexed column in one publish; change index names/locations in another.","Pin index and column names (#[index(name = \"...\")], #[column(name = \"...\")]) so keys stay stable.","Match the toolchain version that created the database before attempting structural index changes.","Dev: spacetime publish --delete-data <db>.","File a SpacetimeDB issue with the plan if clean builds reproduce it."],"exampleFix":"// before: index source renamed AND index/table restructured in one publish\n#[spacetimedb::index(name = \"by_hp\", btree)] // source column `hp` renamed same publish\n\n// after: pin names, publish the source rename alone first\n#[spacetimedb::table(name = \"players\")]\npub struct Player {\n    #[spacetimedb::column(name = \"hp\")]\n    #[spacetimedb::index(btree)]\n    pub hit_points: u32,\n}","handlingStrategy":"fallback","validationCode":"use spacetimedb_schema::auto_migrate::AutoMigrateStep;\nfor step in &plan.steps {\n    if let AutoMigrateStep::ChangeIndexSourceName((namespace, index_name)) = step {\n        if plan.old.find_storing_table(namespace, index_name).is_none() {\n            anyhow::bail!(\"old def lacks index {} - stored schema drift\", index_name);\n        }\n    }\n}","typeGuard":"fn index_in_old_def<'a>(plan: &'a AutoMigratePlan, ns: &str, idx: &str) -> bool {\n    plan.old.find_storing_table(ns, idx).is_some()\n}","tryCatchPattern":"match update_database(&stdb, tx, &plan, ...).await {\n    Err(e) if e.to_string().contains(\"ChangeIndexSourceName\")\n        && e.to_string().contains(\"old module def\") => {\n        // Fall back: republish the exact previous build, then migrate the index stepwise.\n    }\n    result => result?,\n}","preventionTips":["Pin index names with #[index(name = \"...\")] on both module versions.","Do not rename indexed columns and indexes in the same publish.","Track which compiler version produced each database before changing indexes.","Clean-build before publishing index changes."],"tags":["spacetimedb","rust","schema-migration","index-rename","publish"],"backgroundTag":"schema-migration-plan-mismatch","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"}