Files
weichenandCursor 33ee59641f feat(trace): add the project trace ledger and bounded impact walk
Keep item revisions and edge decisions as records, and refuse to treat a missing index as no impact.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-20 15:35:07 +00:00

29 lines
714 B
Go

package traceimpact
import (
"context"
"time"
"github.com/jackc/pgx/v5/pgxpool"
)
// Open uses the record tables when migration 00059 is present.
// Before that migration, it keeps an in-memory ledger so the process can still boot.
func Open(pool *pgxpool.Pool) *Service {
if pool == nil {
return NewMemoryService()
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
var exists bool
err := pool.QueryRow(ctx, `
SELECT EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = 'project_trace_items'
)`).Scan(&exists)
if err != nil || !exists {
return NewMemoryService()
}
return NewService(newPGStore(pool))
}