{"record":{"id":"de1adb93626dfd54","repo":"gastownhall/beads","slug":"uow-init-schema-w","errorCode":null,"errorMessage":"uow: init schema: %w","messagePattern":"uow: init schema: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/uow/dolt_sql_provider.go","lineNumber":409,"sourceCode":"\nfunc openAndInitSchema(ctx context.Context, ep proxy.Endpoint, database, rootUser, rootPassword, tlsConfigName string, teamServer bool, expectedProjectID string, opts providerOptions) (UnitOfWorkProvider, error) {\n\tinitDB, err := openDB(ctx, buildDSN(ep, \"\", rootUser, rootPassword, tlsConfigName))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tinitProvider := &doltSQLProvider{\n\t\tdefaultBranch:     defaultBranch,\n\t\tdb:                initDB,\n\t\tserverEndpoint:    \"tcp:\" + ep.Address(),\n\t\tteamServer:        teamServer,\n\t\texpectedProjectID: expectedProjectID,\n\t\tpreview:           opts.preview,\n\t}\n\n\tif err := initProvider.initSchema(ctx, database); err != nil {\n\t\t_ = initDB.Close()\n\t\treturn nil, fmt.Errorf(\"uow: init schema: %w\", err)\n\t}\n\n\tif err := initDB.Close(); err != nil {\n\t\treturn nil, fmt.Errorf(\"uow: close init db: %w\", err)\n\t}\n\n\tdbConn, err := openDB(ctx, buildDSN(ep, database, rootUser, rootPassword, tlsConfigName))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &doltSQLProvider{\n\t\tdefaultBranch:     defaultBranch,\n\t\tdb:                dbConn,\n\t\tserverEndpoint:    \"tcp:\" + ep.Address(),\n\t\tteamServer:        teamServer,\n\t\texpectedProjectID: expectedProjectID,\n\t\tpreview:           opts.preview,","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/uow/dolt_sql_provider.go#L391-L427","documentation":"This error wraps any failure that occurs while initializing the database schema during NewDoltServerUOWProvider construction. openAndInitSchema connects to the Dolt SQL server without a default database and calls initSchema, which creates the database, tables, and verifies project identity. The connection is closed and the wrapped cause is returned so the caller knows provider startup (not later operation) failed.","triggerScenarios":"Calling NewDoltServerUOWProvider or NewExternalDoltServerUOWProvider when initSchema fails: the SQL server is unreachable or ping fails, CREATE DATABASE / DDL statements fail (permissions, syntax, existing conflicting schema), or the expectedProjectID/preview identity check fails.","commonSituations":"Dolt server not yet running or crashed at startup; root credentials wrong so DDL is denied; a stale or partially-created database from an interrupted run; schema version mismatch after upgrading beads against an old database; expectedProjectID mismatch when pointing at an existing repo's database.","solutions":["Read the wrapped cause after 'uow: init schema:' to identify the actual SQL/permission failure","Verify the Dolt SQL server is running and reachable at the endpoint returned by the proxy","Check root user/password grants allow CREATE DATABASE and DDL","If caused by a corrupt/partial database from a prior failed init, drop the database or remove the server root dir and retry","If it is a project-identity mismatch, confirm expectedProjectID matches the existing database or re-initialize"],"exampleFix":"// before\nprov, err := NewDoltServerUOWProvider(ctx, dir, \"\", log, cfg, backend, \"root\", \"\", \"dolt\", 0, 0, false, projectID)\n// after (empty/nil expectedProjectID or mismatch is a common cause; also ensure server is up)\nif err := waitUntilProxyReady(ctx, ep); err != nil { return err }\nprov, err := NewDoltServerUOWProvider(ctx, dir, \"beads\", log, cfg, backend, \"root\", \"\", \"dolt\", 0, 0, false, projectID)","handlingStrategy":"try-catch","validationCode":"// Go: verify server reachability before constructing\nconn, err := sql.Open(\"mysql\", dsnNoDB)\nif err == nil {\n    if perr := conn.PingContext(ctx); perr != nil { return fmt.Errorf(\"dolt server unreachable: %w\", perr) }\n    conn.Close()\n}","typeGuard":"func isSchemaInitError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"uow: init schema:\")\n}","tryCatchPattern":"prov, err := NewDoltServerUOWProvider(...)\nif err != nil {\n    var ne net.Error\n    if errors.As(err, &ne) { /* server down: retry with backoff */ }\n    if strings.Contains(err.Error(), \"already exists\") { /* drop/reinit stale db */ }\n    return fmt.Errorf(\"provider init failed: %w\", err)\n}","preventionTips":["Health-check the Dolt server endpoint before provider construction","Use a fresh serverRootDir per environment to avoid stale schemas","Pin dolt binary version to the one beads was tested against","Back up expectedProjectID and verify it matches the database before re-init"],"tags":["database","schema","startup","dolt"],"backgroundTag":"schema-init-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}