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>
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package sqlkit
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/steveyegge/beads/internal/storage/issueops"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// AddLabel adds a label to an issue. Passing empty table names lets issueops
|
|
// auto-route between the permanent and wisp label/event tables. Labels cannot
|
|
// change is_blocked, so this uses withWriteTx.
|
|
func (s *Store) AddLabel(ctx context.Context, issueID, label, actor string) error {
|
|
return s.withWriteTx(ctx, func(tx *sql.Tx) error {
|
|
return issueops.AddLabelInTx(ctx, tx, "", "", issueID, label, actor)
|
|
})
|
|
}
|
|
|
|
// RemoveLabel removes a label from an issue. issueops handles wisp routing.
|
|
func (s *Store) RemoveLabel(ctx context.Context, issueID, label, actor string) error {
|
|
return s.withWriteTx(ctx, func(tx *sql.Tx) error {
|
|
return issueops.RemoveLabelInTx(ctx, tx, "", "", issueID, label, actor)
|
|
})
|
|
}
|
|
|
|
// GetLabels retrieves all labels for an issue. The empty table argument routes
|
|
// to the correct label table automatically.
|
|
func (s *Store) GetLabels(ctx context.Context, issueID string) ([]string, error) {
|
|
var labels []string
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
var err error
|
|
labels, err = issueops.GetLabelsInTx(ctx, tx, "", issueID)
|
|
return err
|
|
})
|
|
return labels, err
|
|
}
|
|
|
|
// GetIssuesByLabel retrieves all issues carrying a specific label. Both the
|
|
// id lookup and the issue hydration run in one read tx (a single *sql.Tx serves
|
|
// every table since wisps live in the same DB).
|
|
func (s *Store) GetIssuesByLabel(ctx context.Context, label string) ([]*types.Issue, error) {
|
|
var result []*types.Issue
|
|
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
|
|
ids, err := issueops.GetIssuesByLabelInTx(ctx, tx, label)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(ids) == 0 {
|
|
return nil
|
|
}
|
|
result, err = issueops.GetIssuesByIDsInTx(ctx, tx, ids, nil)
|
|
return err
|
|
})
|
|
return result, err
|
|
}
|