package postgres import ( "context" "errors" "fmt" "github.com/jackc/pgx/v5" "knowledge-governance/internal/workflows/artifactfetch" ) // LoadArtifactFetchManifest resolves one pending intent plus its live source // coordinates for the fetch script, keyed by the connection-stable node id. func (s *Store) LoadArtifactFetchManifest(ctx context.Context, connectionID, nodeID string) (artifactfetch.Manifest, error) { return loadArtifactFetchManifest(ctx, s.db, connectionID, nodeID) } func loadArtifactFetchManifest(ctx context.Context, db interface { QueryRow(context.Context, string, ...any) pgx.Row }, connectionID, nodeID string) (artifactfetch.Manifest, error) { var manifest artifactfetch.Manifest err := db.QueryRow(ctx, `SELECT connection.source_type,connection.name,intent.relative_path,intent.name, intent.size_bytes,intent.modified_at,intent.locator_hash FROM catalog_import_intents intent JOIN source_connections connection ON connection.id=intent.source_connection_id WHERE intent.source_connection_id=$1 AND intent.node_id=$2`, connectionID, nodeID). Scan(&manifest.SourceType, &manifest.SourceName, &manifest.RelativePath, &manifest.Name, &manifest.SizeBytes, &manifest.ModifiedAt, &manifest.LocatorHash) if errors.Is(err, pgx.ErrNoRows) { return artifactfetch.Manifest{}, artifactfetch.ErrManifestGone } if err != nil { return artifactfetch.Manifest{}, fmt.Errorf("load artifact fetch manifest: %w", err) } manifest.ConnectionID = connectionID manifest.NodeID = nodeID return manifest, nil }