- Add ExpectedDB field to RPC Request - Server validates client's expected DB matches daemon's DB - Return clear error on mismatch with both paths - Old clients (no ExpectedDB) still work with warning - Add Path() method to storage.Storage interface - Tests verify cross-database connections rejected Prevents database pollution when client connects to wrong daemon. Amp-Thread-ID: https://ampcode.com/threads/T-c4454192-39c6-4c67-96a9-675cbfc4db92 Co-authored-by: Amp <amp@ampcode.com>
92 lines
3.6 KiB
Go
92 lines
3.6 KiB
Go
// Package storage defines the interface for issue storage backends.
|
|
package storage
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// Storage defines the interface for issue storage backends
|
|
type Storage interface {
|
|
// Issues
|
|
CreateIssue(ctx context.Context, issue *types.Issue, actor string) error
|
|
CreateIssues(ctx context.Context, issues []*types.Issue, actor string) error
|
|
GetIssue(ctx context.Context, id string) (*types.Issue, error)
|
|
UpdateIssue(ctx context.Context, id string, updates map[string]interface{}, actor string) error
|
|
CloseIssue(ctx context.Context, id string, reason string, actor string) error
|
|
SearchIssues(ctx context.Context, query string, filter types.IssueFilter) ([]*types.Issue, error)
|
|
|
|
// Dependencies
|
|
AddDependency(ctx context.Context, dep *types.Dependency, actor string) error
|
|
RemoveDependency(ctx context.Context, issueID, dependsOnID string, actor string) error
|
|
GetDependencies(ctx context.Context, issueID string) ([]*types.Issue, error)
|
|
GetDependents(ctx context.Context, issueID string) ([]*types.Issue, error)
|
|
GetDependencyRecords(ctx context.Context, issueID string) ([]*types.Dependency, error)
|
|
GetAllDependencyRecords(ctx context.Context) (map[string][]*types.Dependency, error)
|
|
GetDependencyTree(ctx context.Context, issueID string, maxDepth int, showAllPaths bool) ([]*types.TreeNode, error)
|
|
DetectCycles(ctx context.Context) ([][]*types.Issue, error)
|
|
|
|
// Labels
|
|
AddLabel(ctx context.Context, issueID, label, actor string) error
|
|
RemoveLabel(ctx context.Context, issueID, label, actor string) error
|
|
GetLabels(ctx context.Context, issueID string) ([]string, error)
|
|
GetIssuesByLabel(ctx context.Context, label string) ([]*types.Issue, error)
|
|
|
|
// Ready Work & Blocking
|
|
GetReadyWork(ctx context.Context, filter types.WorkFilter) ([]*types.Issue, error)
|
|
GetBlockedIssues(ctx context.Context) ([]*types.BlockedIssue, error)
|
|
GetEpicsEligibleForClosure(ctx context.Context) ([]*types.EpicStatus, error)
|
|
|
|
// Events
|
|
AddComment(ctx context.Context, issueID, actor, comment string) error
|
|
GetEvents(ctx context.Context, issueID string, limit int) ([]*types.Event, error)
|
|
|
|
// Comments
|
|
AddIssueComment(ctx context.Context, issueID, author, text string) (*types.Comment, error)
|
|
GetIssueComments(ctx context.Context, issueID string) ([]*types.Comment, error)
|
|
|
|
// Statistics
|
|
GetStatistics(ctx context.Context) (*types.Statistics, error)
|
|
|
|
// Dirty tracking (for incremental JSONL export)
|
|
GetDirtyIssues(ctx context.Context) ([]string, error)
|
|
ClearDirtyIssues(ctx context.Context) error // WARNING: Race condition (bd-52), use ClearDirtyIssuesByID
|
|
ClearDirtyIssuesByID(ctx context.Context, issueIDs []string) error
|
|
|
|
// Config
|
|
SetConfig(ctx context.Context, key, value string) error
|
|
GetConfig(ctx context.Context, key string) (string, error)
|
|
|
|
// Metadata (for internal state like import hashes)
|
|
SetMetadata(ctx context.Context, key, value string) error
|
|
GetMetadata(ctx context.Context, key string) (string, error)
|
|
|
|
// Prefix rename operations
|
|
UpdateIssueID(ctx context.Context, oldID, newID string, issue *types.Issue, actor string) error
|
|
RenameDependencyPrefix(ctx context.Context, oldPrefix, newPrefix string) error
|
|
RenameCounterPrefix(ctx context.Context, oldPrefix, newPrefix string) error
|
|
|
|
// Lifecycle
|
|
Close() error
|
|
|
|
// Database path (for daemon validation)
|
|
Path() string
|
|
}
|
|
|
|
// Config holds database configuration
|
|
type Config struct {
|
|
Backend string // "sqlite" or "postgres"
|
|
|
|
// SQLite config
|
|
Path string // database file path
|
|
|
|
// PostgreSQL config
|
|
Host string
|
|
Port int
|
|
Database string
|
|
User string
|
|
Password string
|
|
SSLMode string
|
|
}
|