{"record":{"id":"fda63ab205b2e078","repo":"gastownhall/beads","slug":"backfill-content-hash-for-migration-d-w","errorCode":null,"errorMessage":"backfill content_hash for migration %d: %w","messagePattern":"backfill content_hash for migration (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/mergesettle.go","lineNumber":780,"sourceCode":"\tfor rows.Next() {\n\t\tvar version sql.NullInt64\n\t\tvar ourHash, theirHash sql.NullString\n\t\tif err := rows.Scan(&version, &ourHash, &theirHash); err != nil {\n\t\t\t_ = rows.Close()\n\t\t\treturn fmt.Errorf(\"scan schema_migrations conflict: %w\", err)\n\t\t}\n\t\tif ourHash.String == \"\" && theirHash.String != \"\" {\n\t\t\tfixes = append(fixes, hashFix{version: version.Int64, hash: theirHash.String})\n\t\t}\n\t}\n\tif err := errors.Join(rows.Err(), rows.Close()); err != nil {\n\t\treturn err\n\t}\n\n\tfor _, f := range fixes {\n\t\tif _, err := db.ExecContext(ctx,\n\t\t\t\"UPDATE schema_migrations SET content_hash = ? WHERE version = ?\", f.hash, f.version); err != nil {\n\t\t\treturn fmt.Errorf(\"backfill content_hash for migration %d: %w\", f.version, err)\n\t\t}\n\t}\n\tif _, err := db.ExecContext(ctx, \"CALL DOLT_CONFLICTS_RESOLVE('--ours', 'schema_migrations')\"); err != nil {\n\t\treturn fmt.Errorf(\"failed to resolve schema_migrations conflicts: %w\", err)\n\t}\n\treturn nil\n}\n\n// resolveConflictDepTarget returns the single non-null dependency target from a\n// conflict row's three typed target columns, following the same precedence as\n// COALESCE(depends_on_issue_id, depends_on_wisp_id, depends_on_external).\nfunc resolveConflictDepTarget(issueTarget, wispTarget, external sql.NullString) (string, bool) {\n\tswitch {\n\tcase issueTarget.Valid:\n\t\treturn issueTarget.String, true\n\tcase wispTarget.Valid:\n\t\treturn wispTarget.String, true\n\tcase external.Valid:","sourceCodeStart":762,"sourceCodeEnd":798,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/mergesettle.go#L762-L798","documentation":"After computing fixes for schema_migrations conflict rows, this code backfills the missing content_hash column by UPDATE-ing each conflicted version with the winning hash. If the UPDATE fails (connection error, lock conflict, engine error), it is wrapped in this message. It indicates the auto-resolve could not normalize the migration table before calling DOLT_CONFLICTS_RESOLVE.","triggerScenarios":"The UPDATE ... SET content_hash = ? WHERE version = ? statement fails — e.g. the content_hash column doesn't exist (older schema_migrations layout), the table is locked by another transaction, or the Dolt engine rejects the write mid-merge.","commonSituations":"Schema drift between clones where one lacks content_hash; a second bd process holding a write lock during merge settlement; embedded-engine transaction conflict on the migrations table.","solutions":["Inspect the wrapped driver error for the real cause (unknown column, lock wait timeout, etc.).","Verify schema_migrations has a content_hash column: SHOW CREATE TABLE schema_migrations.","Retry the merge after ensuring no other bd/dolt process holds a write transaction on the database.","If content_hash is missing on one side, reconcile the migration table schema first, then re-run the merge."],"exampleFix":"// before: silent failure path\nUPDATE schema_migrations SET content_hash = ? WHERE version = ?\n// after: guard existence of the column first\nvar colCount int\n_ = db.QueryRow(\"SELECT COUNT(*) FROM information_schema.columns WHERE table_name='schema_migrations' AND column_name='content_hash'\").Scan(&colCount)\nif colCount == 0 {\n    return fmt.Errorf(\"schema_migrations.content_hash column missing; run bd migrate repair\")\n}","handlingStrategy":"try-catch","validationCode":"var hasCol int\n_ = db.QueryRow(\"SELECT COUNT(*) FROM information_schema.columns WHERE table_name='schema_migrations' AND column_name='content_hash'\").Scan(&hasCol)\nif hasCol == 0 { /* backfill impossible; repair schema first */ }","typeGuard":null,"tryCatchPattern":"if err := TryAutoResolveMergeConflicts(ctx, db); err != nil {\n    if strings.Contains(err.Error(), \"backfill content_hash\") {\n        // check locks / column existence, then retry settle once\n        return retrySettle(ctx, db)\n    }\n    return err\n}","preventionTips":["Ensure both clones run the same migration set before pulling","Avoid concurrent bd processes on the same database","Verify content_hash column exists on schema_migrations"],"tags":["dolt","merge-conflict","sql-update","schema-migrations"],"backgroundTag":"migration-hash-backfill-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}