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>
88 lines
2.7 KiB
Go
88 lines
2.7 KiB
Go
package sqlkit
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// Metadata slots are a gt per-issue key/value store layered over the issue's metadata
|
|
// JSON column. They are pure GetIssue/UpdateIssue manipulation with no version-control
|
|
// dependency, so the logic is identical to the embedded-Dolt reference (slots.go).
|
|
|
|
// SlotSet sets a key/value pair in the issue's metadata JSON.
|
|
func (s *Store) SlotSet(ctx context.Context, issueID, key, value, actor string) error {
|
|
issue, err := s.GetIssue(ctx, issueID)
|
|
if err != nil {
|
|
return fmt.Errorf("getting issue %s: %w", issueID, err)
|
|
}
|
|
|
|
metadata := make(map[string]interface{})
|
|
if len(issue.Metadata) > 0 {
|
|
if err := json.Unmarshal(issue.Metadata, &metadata); err != nil {
|
|
return fmt.Errorf("parsing metadata for %s: %w", issueID, err)
|
|
}
|
|
}
|
|
metadata[key] = value
|
|
|
|
raw, err := json.Marshal(metadata)
|
|
if err != nil {
|
|
return fmt.Errorf("marshaling metadata for %s: %w", issueID, err)
|
|
}
|
|
return s.UpdateIssue(ctx, issueID, map[string]interface{}{"metadata": string(raw)}, actor)
|
|
}
|
|
|
|
// SlotGet retrieves the value of a metadata key from an issue.
|
|
func (s *Store) SlotGet(ctx context.Context, issueID, key string) (string, error) {
|
|
issue, err := s.GetIssue(ctx, issueID)
|
|
if err != nil {
|
|
return "", fmt.Errorf("getting issue %s: %w", issueID, err)
|
|
}
|
|
if len(issue.Metadata) == 0 {
|
|
return "", fmt.Errorf("no slot %q on %s: no metadata", key, issueID)
|
|
}
|
|
|
|
metadata := make(map[string]interface{})
|
|
if err := json.Unmarshal(issue.Metadata, &metadata); err != nil {
|
|
return "", fmt.Errorf("parsing metadata for %s: %w", issueID, err)
|
|
}
|
|
val, ok := metadata[key]
|
|
if !ok {
|
|
return "", fmt.Errorf("no slot %q on %s: key not found", key, issueID)
|
|
}
|
|
if str, ok := val.(string); ok {
|
|
return str, nil
|
|
}
|
|
raw, err := json.Marshal(val)
|
|
if err != nil {
|
|
return "", fmt.Errorf("marshaling slot value for %s.%s: %w", issueID, key, err)
|
|
}
|
|
return string(raw), nil
|
|
}
|
|
|
|
// SlotClear removes a metadata key from an issue. Clearing an absent key (or an issue
|
|
// with no metadata) is a silent no-op.
|
|
func (s *Store) SlotClear(ctx context.Context, issueID, key, actor string) error {
|
|
issue, err := s.GetIssue(ctx, issueID)
|
|
if err != nil {
|
|
return fmt.Errorf("getting issue %s: %w", issueID, err)
|
|
}
|
|
if len(issue.Metadata) == 0 {
|
|
return nil
|
|
}
|
|
|
|
metadata := make(map[string]interface{})
|
|
if err := json.Unmarshal(issue.Metadata, &metadata); err != nil {
|
|
return fmt.Errorf("parsing metadata for %s: %w", issueID, err)
|
|
}
|
|
if _, ok := metadata[key]; !ok {
|
|
return nil
|
|
}
|
|
delete(metadata, key)
|
|
|
|
raw, err := json.Marshal(metadata)
|
|
if err != nil {
|
|
return fmt.Errorf("marshaling metadata for %s: %w", issueID, err)
|
|
}
|
|
return s.UpdateIssue(ctx, issueID, map[string]interface{}{"metadata": string(raw)}, actor)
|
|
}
|