{"record":{"id":"00ddaba8400756ce","repo":"gastownhall/beads","slug":"schema-capture-fresh-bootstrap-identity-database","errorCode":null,"errorMessage":"schema: capture fresh-bootstrap identity: database is %q, want %q","messagePattern":"schema: capture fresh-bootstrap identity: database is %q, want %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/schema/lock.go","lineNumber":120,"sourceCode":"\tconn *sql.Conn,\n\tendpoint string,\n\texpectedDatabase string,\n) (*FreshBootstrapHealCapability, error) {\n\tif endpoint == \"\" {\n\t\treturn nil, errors.New(\"schema: capture fresh-bootstrap identity: empty endpoint\")\n\t}\n\tif expectedDatabase == \"\" {\n\t\treturn nil, errors.New(\"schema: capture fresh-bootstrap identity: empty database name\")\n\t}\n\n\tvar databaseName, serverUUID, initialHead string\n\tif err := conn.QueryRowContext(ctx,\n\t\t\"SELECT DATABASE(), @@server_uuid, DOLT_HASHOF('HEAD')\",\n\t).Scan(&databaseName, &serverUUID, &initialHead); err != nil {\n\t\treturn nil, fmt.Errorf(\"schema: capture fresh-bootstrap identity: %w\", err)\n\t}\n\tif databaseName != expectedDatabase {\n\t\treturn nil, fmt.Errorf(\"schema: capture fresh-bootstrap identity: database is %q, want %q\", databaseName, expectedDatabase)\n\t}\n\tif serverUUID == \"\" {\n\t\treturn nil, errors.New(\"schema: capture fresh-bootstrap identity: empty server UUID\")\n\t}\n\tif initialHead == \"\" {\n\t\treturn nil, errors.New(\"schema: capture fresh-bootstrap identity: empty initial HEAD\")\n\t}\n\n\tvar commitCount, dirtyCount int\n\tif err := conn.QueryRowContext(ctx, \"SELECT COUNT(*) FROM dolt_log\").Scan(&commitCount); err != nil {\n\t\treturn nil, fmt.Errorf(\"schema: verify fresh-bootstrap history: %w\", err)\n\t}\n\tif commitCount != 1 {\n\t\treturn nil, fmt.Errorf(\"schema: verify fresh-bootstrap history: got %d commits, want 1\", commitCount)\n\t}\n\tif err := conn.QueryRowContext(ctx, \"SELECT COUNT(*) FROM dolt_status\").Scan(&dirtyCount); err != nil {\n\t\treturn nil, fmt.Errorf(\"schema: verify fresh-bootstrap working set: %w\", err)\n\t}","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/schema/lock.go#L102-L138","documentation":"After the identity probe, the library checks that the session's current database (DATABASE()) equals the database name the caller said it just created. A mismatch means the pinned session is attached to a different database than expected, so capture refuses to issue reset authority for the wrong target.","triggerScenarios":"Calling CaptureFreshBootstrapHealCapability with expectedDatabase not matching the session's selected database — e.g. the DSN names database A while the caller passes B, or the locked preparation created one database but did not USE the one passed in.","commonSituations":"Config mistakes where the DSN database differs from the configured beads database name; a preparation hook that CREATE DATABASE'd but forgot `USE`; case-sensitivity differences in database names on Linux servers.","solutions":["Make the expectedDatabase argument exactly match the database the connection is attached to (DSN db or explicit USE).","Ensure the locked preparation runs `USE \\`<db>\\`` after CREATE DATABASE before capture.","Check database-name case matches the server's (Linux Dolt servers are case-sensitive).","Log DATABASE() alongside your configured name to spot config drift."],"exampleFix":"// before\nschema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, \"Beads\") // db is \"beads\"\n// after\nschema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, cfg.DatabaseName) // exact name used in DSN/CREATE DATABASE","handlingStrategy":"validation","validationCode":"var current string\nif err := conn.QueryRowContext(ctx, \"SELECT DATABASE()\").Scan(&current); err != nil { return err }\nif current != dbName {\n    return fmt.Errorf(\"session on %q, want %q — add USE or fix DSN\", current, dbName)\n}","typeGuard":null,"tryCatchPattern":"cap, err := schema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, dbName)\nif err != nil && strings.Contains(err.Error(), \"database is\") {\n    // wrong database selected: fix DSN/USE and retry\n}","preventionTips":["Use a DSN that names the database and pass that same name as expectedDatabase.","Issue `USE \\`db\\`` in locked preparation right after CREATE DATABASE.","Match database-name case exactly (Linux servers are case-sensitive).","Centralize the database name in one config value."],"tags":["go","database","dolt","configuration","schema-migration"],"backgroundTag":"database-name-mismatch","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}