{"record":{"id":"ca85454edbfea75c","repo":"clockworklabs/SpacetimeDB","slug":"precheck-sequence-sequence-name-not-found-in","errorCode":null,"errorMessage":"Precheck: sequence `{sequence_name}` not found in new module def","messagePattern":"Precheck: sequence `(.+?)` not found in new module def","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":220,"sourceCode":"/// Automatically migrate a database.\nfn auto_migrate_database(\n    stdb: &RelationalDB,\n    tx: &mut MutTxId,\n    auth_ctx: AuthCtx,\n    plan: AutoMigratePlan,\n    logger: &dyn UpdateLogger,\n) -> anyhow::Result<UpdateResult> {\n    log::info!(\"Running database update prechecks: {}\", stdb.database_identity());\n    // We used to memoize all table schemas upfront, which cause issue #3441.\n    // Schema should be queries only when needed to ensure that any schema changes made during earlier migration steps are visible\n    // to later steps.\n\n    for precheck in plan.prechecks {\n        match precheck {\n            spacetimedb_schema::auto_migrate::AutoMigratePrecheck::CheckAddSequenceRangeValid(key) => {\n                let (namespace, sequence_name) = key;\n                let (_, table_def) = plan.new.find_storing_table(namespace, sequence_name).ok_or_else(|| {\n                    anyhow::anyhow!(\"Precheck: sequence `{sequence_name}` not found in new module def\")\n                })?;\n                let sequence_def: &SequenceDef = plan.new.lookup(key).ok_or_else(|| {\n                    anyhow::anyhow!(\"Precheck: sequence `{sequence_name}` not found in new module def\")\n                })?;\n                let table_full_name = joined(namespace, &table_def.name);\n                let table_id = stdb.table_id_from_name_mut(tx, &table_full_name)?.unwrap();\n\n                let ty = table_def\n                    .get_column(sequence_def.column)\n                    .ok_or_else(|| {\n                        anyhow::anyhow!(\"Precheck failed: added sequence {sequence_name} refers to unknown column\")\n                    })?\n                    .ty\n                    .clone();\n\n                // Convert `SequenceDef` min/max to `AlgebraicValue`s of the correct type.\n                let min = ty\n                    .saturating_value_from_i128(sequence_def.min_value.unwrap_or(1))","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L202-L238","documentation":"Auto-migrate precheck CheckAddSequenceRangeValid: find_storing_table(namespace, sequence_name) failed, so no table in the new module def is responsible for storing the sequence named in the plan. The migration plan and the new def it was computed from are out of sync — an internal invariant break rather than user input error.","triggerScenarios":"A MigratePlan whose prechecks were computed from a different ModuleDef than plan.new; hand-constructed AutoMigratePrecheck entries; a bug in spacetimedb_schema's plan generation pairing a sequence with a table that no longer stores it.","commonSituations":"Custom tooling that assembles AutoMigratePlan pieces from multiple def versions; upstream diff bugs after schema-dsl changes; tests that build plans manually.","solutions":["Recompute the whole migration plan from the same ModuleDef you pass as plan.new","If the plan came from spacetimedb_schema's differ, report upstream with both module defs and the key (namespace, sequence_name)","Never hand-build AutoMigratePrecheck entries; derive them from the diff"],"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(\"Precheck: sequence\") => {\n        // plan/def desync: rebuild the plan from one consistent def, then retry once\n        let plan2 = rebuild_plan_from(new_def)?;\n        auto_migrate_database(&stdb, &mut tx, auth, &plan2, &logger)\n    }\n    r => r,\n}","preventionTips":["Derive prechecks and plan.new from the same ModuleDef instance","Never hand-assemble AutoMigratePrecheck entries","Pin one def revision for diff and apply within a publish"],"tags":["rust","spacetimedb","migration","sequence","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-14T00:17:10.932Z"}