{"record":{"id":"d8a8b07a00576280","repo":"gastownhall/beads","slug":"checking-s-for-the-pre-0058-repair-w","errorCode":null,"errorMessage":"checking %s for the pre-0058 repair: %w","messagePattern":"checking (.+?) for the pre-0058 repair: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/wisp_dep_forward_repair.go","lineNumber":130,"sourceCode":"\t{\"uk_wisp_dep_external_target\", \"ADD UNIQUE KEY uk_wisp_dep_external_target (issue_id, depends_on_external)\"},\n\t{\"idx_wisp_dep_type_issue\", \"ADD INDEX idx_wisp_dep_type_issue (type, depends_on_issue_id)\"},\n\t{\"idx_wisp_dep_type_wisp\", \"ADD INDEX idx_wisp_dep_type_wisp (type, depends_on_wisp_id)\"},\n\t{\"idx_wisp_dep_type_external\", \"ADD INDEX idx_wisp_dep_type_external (type, depends_on_external)\"},\n}\n\n// repairWispDependenciesForwardShape is the pre-0058 repair. It no-ops on every\n// population except the one 0058 cannot serve: no-ops when the table or either\n// referenced table is absent, when the table is already in the final shape, and\n// on a fresh store (which never had the generated column, so 0058 applies to it\n// cleanly).\nfunc repairWispDependenciesForwardShape(ctx context.Context, db DBConn) error {\n\t// Both referenced tables must exist before any foreign key can be added.\n\t// 0058 carries the same @has_wisps/@has_issues guards; a database missing\n\t// one is left untouched rather than assumed into a shape it may not have.\n\tfor _, t := range []string{wispDepTable, \"wisps\", \"issues\"} {\n\t\texists, err := schemaTableExists(ctx, db, t)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"checking %s for the pre-0058 repair: %w\", t, err)\n\t\t}\n\t\tif !exists {\n\t\t\treturn nil\n\t\t}\n\t}\n\n\tneeded, err := wispDepNeedsForwardRepair(ctx, db)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !needed {\n\t\treturn nil\n\t}\n\n\tif err := deleteWispDepRowsRejectedByFinalShape(ctx, db); err != nil {\n\t\treturn err\n\t}\n\tif err := dropWispDepLegacyShape(ctx, db); err != nil {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/wisp_dep_forward_repair.go#L112-L148","documentation":"This error wraps a failure while probing whether a table (wisp_dependencies, wisps, or issues) exists, via schemaTableExists, before running the pre-0058 forward-shape repair. The repair bails out silently (nil) when a table is missing, but if the existence CHECK itself errors — typically a metadata query failure against the Dolt/MySQL information schema — the underlying error is wrapped with this message. It indicates the repair could not even determine the database's shape.","triggerScenarios":"repairWispDependenciesForwardShape calls schemaTableExists(ctx, db, t) and the underlying SHOW FULL TABLES / information_schema query returns an error (connection drop, permissions, corrupt metadata, server shutdown mid-migration).","commonSituations":"Database connection lost during startup migration; the bd process lacks privileges to read information_schema; Dolt server restarting while an upgrade runs; metadata corruption after a crashed migration.","solutions":["Check the wrapped underlying error (%w) for the real cause — usually connectivity or permissions.","Verify the DB connection is alive and the server is up, then re-run `bd` so the repair retries.","Confirm the user has SELECT on information_schema / SHOW TABLES privileges.","If metadata is corrupt, restore from backup or re-initialize the database and re-import from issues.jsonl export."],"exampleFix":"// before (caller ignoring migration failure)\nrepairWispDependenciesForwardShape(ctx, db) // panic: checking wisps for the pre-0058 repair: driver: bad connection\n// after\nif err := repairWispDependenciesForwardShape(ctx, db); err != nil {\n    log.Fatalf(\"schema repair failed, check DB connectivity: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"// before relying on the repair\nrows, err := db.QueryContext(ctx, \"SELECT 1 FROM information_schema.TABLES WHERE TABLE_NAME = 'wisp_dependencies'\")\nif err != nil {\n    log.Fatalf(\"metadata unreachable — check connectivity/privileges before running bd: %v\", err)\n}\nrows.Close()","typeGuard":null,"tryCatchPattern":"if err := repairWispDependenciesForwardShape(ctx, db); err != nil {\n    var driverErr driver.Error\n    if errors.As(err, &driverErr) && driverErr.Code() == errnoBadConnection {\n        // reconnect and retry the guarded repair\n    }\n    return fmt.Errorf(\"pre-0058 repair aborted during table check: %w\", err)\n}","preventionTips":["Run migrations on a healthy, verified DB connection (ping first).","Grant the migration user SELECT on information_schema.","Avoid killing the process mid-upgrade; let the guarded repair finish.","Keep Dolt server version compatible with the bd schema migrations."],"tags":["database","schema-repair","migration","introspection"],"backgroundTag":"schema-introspection-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}