Skip to content

epic: Complete database abstraction layer — eliminate sqlx leaks, migrate to generics #2385

@bug-ops

Description

@bug-ops

Problem

The zeph-db crate (introduced in PRs #2371, #2372, #2379) provides a database abstraction layer, but the abstraction is incomplete and leaky:

  1. 6 consumer crates hardcode sqlx with features = ["sqlite"], bypassing zeph-db entirely
  2. The design uses #[cfg] type aliases instead of Rust generics (violates established project feedback)
  3. Building with --features postgres (without sqlite) will fail in all consumer crates
  4. zeph-memory has 367 direct sqlx:: occurrences across 31 files alongside zeph-db imports

Affected Crates

  • zeph-memory (Cargo.toml:28 — hardcoded sqlx/sqlite)
  • zeph-core (Cargo.toml:50 — hardcoded sqlx/sqlite)
  • zeph-orchestration (Cargo.toml:19 — hardcoded sqlx/sqlite)
  • zeph-index (Cargo.toml:23 — hardcoded sqlx/sqlite)
  • zeph-mcp (Cargo.toml:35 — hardcoded sqlx/sqlite)
  • zeph-scheduler (Cargo.toml:23 — hardcoded sqlx/sqlite)

Implementation Phases

  • Phase 1: Remove direct sqlx deps from consumer crates, re-export from zeph-db, add feature propagation
  • Phase 2: Migrate from #[cfg] type aliases to Pool<DB> generics per feedback_db_generics.md
  • Phase 3: Port test infrastructure, add postgres CI matrix

Architectural Review

Full report: .local/handoff/db-arch-review.md

Key findings:

  • Qdrant placement in zeph-memory is CORRECT (do not move to zeph-db)
  • VectorStore trait abstraction is well-designed
  • Dialect trait and FTS helpers are solid
  • sql! macro postgres variant has a memory leak (Box::leak without LazyLock caching)
  • Feature flags: postgres correctly excluded from full, mutual exclusion enforced
  • Pattern compliance: thiserror, no async-trait, rustls, no hardcoded models — all pass

Metadata

Metadata

Assignees

Labels

P1High ROI, low complexity — do next sprintarchitectureArchitecture improvementsenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions