gastownhall/beads · error

schema: capture fresh-bootstrap identity: database is %q, wa

Error message

schema: capture fresh-bootstrap identity: database is %q, want %q

What it means

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.

Source

Thrown at internal/storage/schema/lock.go:120

	conn *sql.Conn,
	endpoint string,
	expectedDatabase string,
) (*FreshBootstrapHealCapability, error) {
	if endpoint == "" {
		return nil, errors.New("schema: capture fresh-bootstrap identity: empty endpoint")
	}
	if expectedDatabase == "" {
		return nil, errors.New("schema: capture fresh-bootstrap identity: empty database name")
	}

	var databaseName, serverUUID, initialHead string
	if err := conn.QueryRowContext(ctx,
		"SELECT DATABASE(), @@server_uuid, DOLT_HASHOF('HEAD')",
	).Scan(&databaseName, &serverUUID, &initialHead); err != nil {
		return nil, fmt.Errorf("schema: capture fresh-bootstrap identity: %w", err)
	}
	if databaseName != expectedDatabase {
		return nil, fmt.Errorf("schema: capture fresh-bootstrap identity: database is %q, want %q", databaseName, expectedDatabase)
	}
	if serverUUID == "" {
		return nil, errors.New("schema: capture fresh-bootstrap identity: empty server UUID")
	}
	if initialHead == "" {
		return nil, errors.New("schema: capture fresh-bootstrap identity: empty initial HEAD")
	}

	var commitCount, dirtyCount int
	if err := conn.QueryRowContext(ctx, "SELECT COUNT(*) FROM dolt_log").Scan(&commitCount); err != nil {
		return nil, fmt.Errorf("schema: verify fresh-bootstrap history: %w", err)
	}
	if commitCount != 1 {
		return nil, fmt.Errorf("schema: verify fresh-bootstrap history: got %d commits, want 1", commitCount)
	}
	if err := conn.QueryRowContext(ctx, "SELECT COUNT(*) FROM dolt_status").Scan(&dirtyCount); err != nil {
		return nil, fmt.Errorf("schema: verify fresh-bootstrap working set: %w", err)
	}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Make the expectedDatabase argument exactly match the database the connection is attached to (DSN db or explicit USE).
  2. Ensure the locked preparation runs `USE \`<db>\`` after CREATE DATABASE before capture.
  3. Check database-name case matches the server's (Linux Dolt servers are case-sensitive).
  4. Log DATABASE() alongside your configured name to spot config drift.

Example fix

// before
schema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, "Beads") // db is "beads"
// after
schema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, cfg.DatabaseName) // exact name used in DSN/CREATE DATABASE
Defensive patterns

Strategy: validation

Validate before calling

var current string
if err := conn.QueryRowContext(ctx, "SELECT DATABASE()").Scan(&current); err != nil { return err }
if current != dbName {
    return fmt.Errorf("session on %q, want %q — add USE or fix DSN", current, dbName)
}

Try / catch

cap, err := schema.CaptureFreshBootstrapHealCapability(ctx, conn, endpoint, dbName)
if err != nil && strings.Contains(err.Error(), "database is") {
    // wrong database selected: fix DSN/USE and retry
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/00ddaba8400756ce. Report an issue: GitHub.