{"record":{"id":"5cf8f6cd64411f54","repo":"gastownhall/beads","slug":"staging-migrations-w","errorCode":null,"errorMessage":"staging migrations: %w","messagePattern":"staging migrations: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/schema.go","lineNumber":732,"sourceCode":"\t}\n\tif err := unstageIgnoredTables(ctx, db); err != nil {\n\t\treturn applied, fmt.Errorf(\"unstaging ignored migration tables: %w\", err)\n\t}\n\n\tif applied == 0 && !backfilled && appliedIgnored == 0 && !mainColumnAdded && !ignoredColumnAdded {\n\t\treturn applied, nil\n\t}\n\tchangedDirtyTables, err := changedDirtyTableSignatures(ctx, db, dirtyBeforeSignatures)\n\tif err != nil {\n\t\treturn applied, fmt.Errorf(\"checking pre-existing dirty table diffs: %w\", err)\n\t}\n\tif len(changedDirtyTables) > 0 {\n\t\treturn applied, fmt.Errorf(\"pre-existing dirty tables changed during schema migration: %s\", strings.Join(changedDirtyTables, \", \"))\n\t}\n\n\tstaged, err := stageSchemaTables(ctx, db, dirtyBefore)\n\tif err != nil {\n\t\treturn applied, fmt.Errorf(\"staging migrations: %w\", err)\n\t}\n\tif !staged {\n\t\treturn applied, nil\n\t}\n\tif err := DrainCall(ctx, db, \"CALL DOLT_COMMIT('-m', 'schema: apply migrations')\"); err != nil {\n\t\tif !strings.Contains(strings.ToLower(err.Error()), \"nothing to commit\") {\n\t\t\treturn applied, fmt.Errorf(\"committing migrations: %w\", err)\n\t\t}\n\t}\n\n\treturn applied, nil\n}\n\nfunc migrationWorkNeeded(ctx context.Context, db DBConn) (bool, error) {\n\tif !mainSource.atLatest(ctx, db) || !ignoredSource.atLatest(ctx, db) {\n\t\treturn true, nil\n\t}\n\t// A database already at the latest numbered migration still needs work if it","sourceCodeStart":714,"sourceCodeEnd":750,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/schema.go#L714-L750","documentation":"Once the migration pass is verified, MigrateUp calls stageSchemaTables to stage the migrated schema tables in the Dolt working set so they can be committed. This error wraps a failure of that staging step — the schema changes are applied but could not be staged for the subsequent DOLT_COMMIT, leaving them uncommitted in the working set. The pass aborts without committing.","triggerScenarios":"Calling MigrateUp/MigrateUpWithLock when stageSchemaTables(ctx, db, dirtyBefore) errors — SQL failures issuing the staging statements (dolt add equivalents), permission failures, connection drops, or working-set conflicts while staging the migrated tables.","commonSituations":"Database user lacking privileges to stage/alter the working set, a corrupted or conflicted Dolt working set from a prior crash, concurrent sessions mutating the working set during staging, or connection instability on large schema changes.","solutions":["Check the wrapped cause (%w) for the exact SQL error from stageSchemaTables and fix it (permissions, conflict, connection)","Inspect the Dolt working set (dolt status) for conflicts or corruption; resolve or reset it, then re-run MigrateUp","Ensure no other session is writing to the working set during migration (use MigrateUpWithLock and stop competing writers)","Verify the DB user can perform the staging DDL/DML on the schema tables","Re-run MigrateUp once staging can succeed so the schema changes get committed"],"exampleFix":"// before: read-only-ish user cannot stage migrated tables\nGRANT SELECT, INSERT, UPDATE ON *.* TO 'bd'@'%';\n// after: grant the DDL/staging privileges migrations need\nGRANT ALL PRIVILEGES ON *.* TO 'bd'@'%';","handlingStrategy":"try-catch","validationCode":"// Pre-flight: session can write to the working set and it is conflict-free\nrows, err := db.QueryContext(ctx, \"SELECT conflict FROM dolt_status\")\nif err != nil {\n    return fmt.Errorf(\"working set not writable: %w\", err)\n}\ndefer rows.Close()\nfor rows.Next() {\n    var conflict bool\n    if err := rows.Scan(&conflict); err == nil && conflict {\n        return errors.New(\"working set has conflicts; resolve before migrating\")\n    }\n}","typeGuard":null,"tryCatchPattern":"applied, err := schema.MigrateUpWithLock(ctx, db)\nif err != nil {\n    if strings.Contains(err.Error(), \"staging migrations:\") {\n        cause := errors.Unwrap(err)\n        // Schema applied but not staged/committed; safe to retry after fix\n        return fmt.Errorf(\"schema staged failed (%v); resolve and re-run MigrateUp\", cause)\n    }\n    return err\n}","preventionTips":["Grant the migration user privileges needed to stage/commit the working set","Resolve working-set conflicts and repair corruption (dolt status / dolt conflicts) before upgrading","Serialize migrations via MigrateUpWithLock so concurrent sessions cannot interleave with staging","Retry MigrateUp after fixing transient failures — the schema changes persist in the working set until staged and committed"],"tags":["database","migration","staging","dolt"],"backgroundTag":"schema-staging-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}