{"record":{"id":"79876bc701dc1895","repo":"gastownhall/beads","slug":"adding-issues-s-for-migration-0053-w","errorCode":null,"errorMessage":"adding issues.%s for migration 0053: %w","messagePattern":"adding issues\\.(.+?) for migration 0053: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/migration_repairs.go","lineNumber":594,"sourceCode":"func ensureIssuesRigColumns(ctx context.Context, db DBConn) error {\n\tcolumns := []struct{ name, definition string }{\n\t\t{\"hook_bead\", \"VARCHAR(255) DEFAULT ''\"},\n\t\t{\"role_bead\", \"VARCHAR(255) DEFAULT ''\"},\n\t\t{\"agent_state\", \"VARCHAR(32) DEFAULT ''\"},\n\t\t{\"last_activity\", \"DATETIME\"},\n\t\t{\"role_type\", \"VARCHAR(32) DEFAULT ''\"},\n\t\t{\"rig\", \"VARCHAR(255) DEFAULT ''\"},\n\t}\n\tfor _, col := range columns {\n\t\tpresent, err := schemaColumnExists(ctx, db, \"issues\", col.name)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"checking issues.%s: %w\", col.name, err)\n\t\t}\n\t\tif present {\n\t\t\tcontinue\n\t\t}\n\t\tif _, err := db.ExecContext(ctx, \"ALTER TABLE issues ADD COLUMN \"+col.name+\" \"+col.definition); err != nil {\n\t\t\treturn fmt.Errorf(\"adding issues.%s for migration 0053: %w\", col.name, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// ensureWispDependenciesSplitTargets repairs #4555: a mixed-vintage local\n// wisp_dependencies table can have the post-0005 id column while still lacking\n// one or more split target columns. Migration 0053 reads those columns when it\n// repairs rig wisps, so add the missing columns and backfill them from the\n// legacy depends_on_id column when that source column is still available.\n//\n// Column presence is not, by itself, proof the backfill below ever ran: a\n// process killed after the ADD COLUMNs but before the backfill leaves all\n// three target columns present but unpopulated. Re-entry must not\n// short-circuit on \"columns exist\" -- it re-runs the backfill whenever\n// depends_on_id (the legacy source the backfill reads from) is still around,\n// which is itself idempotent (each statement below is scoped to the rows it\n// hasn't yet filled in). Skipping this matters because a later ignored","sourceCodeStart":576,"sourceCodeEnd":612,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/migration_repairs.go#L576-L612","documentation":"Wraps failure of `ALTER TABLE issues ADD COLUMN <name> <definition>` when the 0053 repair adds a missing rig column (`role_type` VARCHAR(32) DEFAULT '' or `rig` VARCHAR(255) DEFAULT ''). Only reached when the column was confirmed absent, so this is the ALTER itself failing.","triggerScenarios":"ensureIssuesRigColumns finds a column missing and the ADD COLUMN fails: issues table locked by a concurrent writer, missing ALTER privilege, disk full during table rebuild, Dolt transaction conflict, or connection drop on a large issues table.","commonSituations":"Upgrade of a large production beads database interrupted by process supervisors; simultaneous bd invocations during first run after upgrade; low-disk CI containers.","solutions":["Ensure exclusive access (stop other bd processes) and rerun; presence checks make it idempotent","Free disk space before retrying — ALTER rebuilds the table","Grant ALTER privilege to the database user if the wrapped error says denied","Run the migration in a maintenance window for large databases and suppress restart loops"],"exampleFix":"// before: concurrent bd processes deadlock the ALTER\npkill -f 'bd ' ; bd ready   // completes column add\n// after: single clean run\nbd ready","handlingStrategy":"retry","validationCode":"df -h /path/to/db\nbd dolt sql -q \"SHOW COLUMNS FROM issues LIKE 'rig'\" || echo 'issues table busy/unreachable'","typeGuard":null,"tryCatchPattern":"if err := ensureSchema(ctx, db); err != nil {\n    if strings.Contains(err.Error(), \"adding issues.\") && strings.Contains(err.Error(), \"migration 0053\") {\n        return retryWithBackoff(ensureSchema) // idempotent: re-checks column presence\n    }\n    return err\n}","preventionTips":["Run upgrades with exclusive database access","Maintain disk headroom for ALTER table rebuilds","Use a maintenance window for large issues tables","Grant ALTER privilege to the upgrade account"],"tags":["database","migration","alter-table","sql"],"backgroundTag":"migration-backfill-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}