beads/internal/storage/sqlkit/annotations.go
Test User 1fc38ba778 feat: choose your own storage backend (Postgres / MySQL / SQLite) — rebased on main
Rebase of PR #4601 (feat/choose-your-own-backend) onto current origin/main,
squashed to a single commit because the original 73-commit history built and then
removed the uowStore derisk spike incrementally, which does not replay cleanly
over the 125 commits main has since advanced (notably #4679, the ready-work
counts fix, which merged to main and is now inherited rather than re-applied).
The full pre-rebase history remains on the original branch tip for reference.

Contents (multi-backend feature + the six review follow-ups):
- bd init --backend=postgres|mysql|sqlite provisioning behind the Dolt-parity
  seam; the three SQL backends share *sqlkit.Store over pluggable dialects and
  carry a generated typed-unsupported shell for the non-core surface.
- Passwords in init DSNs are redacted before persisting to metadata.json (driver
  parser + re-parse verification), with a negative-test matrix proving no secret
  survives (pgdialect + mysql).
- The uowStore derisk spike and its report artifacts are removed; the shell
  generator now lives in internal/storage/unsupportedgen (neutral name).
- Compile-time guard `var _ storage.DoltStorage = (*Store)(nil)` on each backend
  plus a regen-idempotence test keep the generated skip lists honest.
- sqlkit exposes CountReadyWork so every SQL backend satisfies
  storage.ReadyWorkCounter and inherits the shared page-pushed ready-counts path.
- Commercial/product names scrubbed from the feature's own code for vendor
  neutrality.

Rebase reconciliations: adopted main's metadata-load hardening in the store
factories alongside the backend dispatch; combined the config interface
(GetMetadata + ReconcileVersion) and the conformance registrations (ReadyCounts +
Claim/lease); took main's versions of the shared-infra concurrency (uow
doltserver_tx) and delete-cascade (domain/issue_delete) evolutions; implemented
the interface's new UnclaimIssue on sqlkit (delegating to issueops) and added it
to the skip lists.

Verified: go build (cgo + CGO_ENABLED=0) and go vet clean; unit tests
(sqlbuild/issueops/pgdialect/mysql/unsupportedgen) and the SQLite conformance
suite green (RunAll, incl. ReadyCounts equivalence and Claim/lease on the real
sqlkit backend).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-10 17:44:37 +00:00

89 lines
2.8 KiB
Go

package sqlkit
import (
"context"
"database/sql"
"github.com/steveyegge/beads/internal/storage/issueops"
"github.com/steveyegge/beads/internal/types"
)
// AddIssueComment adds a structured comment to an issue, stamped with the
// current UTC time. issueops verifies the issue exists and wisp-routes.
func (s *Store) AddIssueComment(ctx context.Context, issueID, author, text string) (*types.Comment, error) {
var result *types.Comment
err := s.withWriteTx(ctx, func(tx *sql.Tx) error {
var e error
result, e = issueops.AddIssueCommentInTx(ctx, tx, issueID, author, text)
return e
})
return result, err
}
// GetIssueComments returns all comments on an issue, oldest first.
func (s *Store) GetIssueComments(ctx context.Context, issueID string) ([]*types.Comment, error) {
var result []*types.Comment
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
var e error
result, e = issueops.GetIssueCommentsInTx(ctx, tx, issueID)
return e
})
return result, err
}
// GetEvents returns the audit-trail events for an issue (limit <= 0 = all).
func (s *Store) GetEvents(ctx context.Context, issueID string, limit int) ([]*types.Event, error) {
var result []*types.Event
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
var e error
result, e = issueops.GetEventsInTx(ctx, tx, issueID, limit)
return e
})
return result, err
}
// CountIssueComments returns the number of comments on an issue. Intentionally
// not wisp-routed — mirrors the dolt body for oracle parity.
func (s *Store) CountIssueComments(ctx context.Context, issueID string) (int64, error) {
var n int64
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
return tx.QueryRowContext(ctx,
"SELECT count(*) FROM comments WHERE issue_id = ?", issueID).Scan(&n)
})
return n, err
}
// CountEvents returns the number of audit events for an issue, capped at limit
// (or unbounded if limit == 0). Not wisp-routed, matching the dolt body.
func (s *Store) CountEvents(ctx context.Context, issueID string, limit int) (int64, error) {
var n int64
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
return tx.QueryRowContext(ctx,
"SELECT count(*) FROM events WHERE issue_id = ?", issueID).Scan(&n)
})
if err != nil {
return 0, err
}
if limit > 0 && n > int64(limit) {
n = int64(limit)
}
return n, nil
}
// SetLocalMetadata writes a clone-local (dolt-ignored) metadata value.
func (s *Store) SetLocalMetadata(ctx context.Context, key, value string) error {
return s.withWriteTx(ctx, func(tx *sql.Tx) error {
return issueops.SetLocalMetadataInTx(ctx, tx, key, value)
})
}
// GetLocalMetadata reads a clone-local metadata value ("" when absent).
func (s *Store) GetLocalMetadata(ctx context.Context, key string) (string, error) {
var v string
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
var e error
v, e = issueops.GetLocalMetadataInTx(ctx, tx, key)
return e
})
return v, err
}