Move bizdev/freedoc/intent/projectworkflow/squad giant files into ≤800-line use-case siblings without behavior change; short tests green.
51 lines
2.5 KiB
Go
51 lines
2.5 KiB
Go
package projectworkflow
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// Store 数据存储层接口
|
|
type Store interface {
|
|
CreateProject(ctx context.Context, p *Project) (*Project, error)
|
|
GetProjectByID(ctx context.Context, id int64) (*Project, error)
|
|
GetProjectByCode(ctx context.Context, code string) (*Project, error)
|
|
GetProjectByClientKey(ctx context.Context, creatorUserID int64, clientKey string) (*Project, error)
|
|
FindProjectByCreatorAndName(ctx context.Context, creatorUserID int64, name string) (*Project, error)
|
|
FindProjectByName(ctx context.Context, name string) (*Project, error)
|
|
ListAllProjects(ctx context.Context) ([]*Project, error)
|
|
ListProjectsForUser(ctx context.Context, userID int64) ([]*Project, error)
|
|
ListProjectWorkflows(ctx context.Context, projectID int64) ([]*ProjectWorkflow, error)
|
|
EnsureProjectWorkflows(ctx context.Context, projectID int64, defaultKeys []string) error
|
|
UpdateActiveWorkflow(ctx context.Context, projectID int64, toWorkflowKey string, expectedVersion int, changedBy int64, reason string) (*Project, *WorkflowActivationAudit, error)
|
|
|
|
CreateWorkflowRun(ctx context.Context, run *WorkflowRun) (*WorkflowRun, error)
|
|
UpdateWorkflowRun(ctx context.Context, runID string, status string, outputDocID string, summary string, errMsg string) error
|
|
GetWorkflowRun(ctx context.Context, runID string) (*WorkflowRun, error)
|
|
ListWorkflowRuns(ctx context.Context, projectID int64, workflowKey string, limit int) ([]*WorkflowRun, error)
|
|
|
|
RecordLineage(ctx context.Context, lineage *DocumentLineage) error
|
|
GetLineageForDownstream(ctx context.Context, docID string, version int) ([]*DocumentLineage, error)
|
|
// GetLineageForProjectDownstream 只返回属于该项目的边,避免用他项目 doc_id 读出血缘。
|
|
GetLineageForProjectDownstream(ctx context.Context, projectID int64, docID string, version int) ([]*DocumentLineage, error)
|
|
GetLineagesForUpstream(ctx context.Context, upstreamDocID string) ([]*DocumentLineage, error)
|
|
MarkDownstreamStale(ctx context.Context, upstreamDocID string, staleReason string) ([]*DocumentLineage, error)
|
|
}
|
|
|
|
// NewStore 根据 pgxpool 是否可用构建 PGStore 或内存 Fallback Store
|
|
func NewStore(pool *pgxpool.Pool) Store {
|
|
if pool != nil {
|
|
return &pgStore{pool: pool}
|
|
}
|
|
return newMemStore()
|
|
}
|
|
|
|
// =============================================================================
|
|
// PostgreSQL 权威持久化实现
|
|
// =============================================================================
|
|
|
|
type pgStore struct {
|
|
pool *pgxpool.Pool
|
|
}
|