Skip to content

DB layer cleanup: pool config, sql! macro, error consolidation, edge upsert (Phase 2) #2387

@bug-ops

Description

@bug-ops

Parent epic: #2385

Scope Change

Originally scoped as generics migration. After adversarial critique review, the generics migration is deferred to backlog (P4) because:

  1. sqlx::migrate! is monomorphic — requires #[cfg] per backend
  2. Trait bounds explosion (5 HRTB bounds in FullDriver already)
  3. The #[cfg] type alias approach is pragmatically correct for pre-v1.0

This issue is repurposed for concrete code quality and performance fixes.

Changes

Pool Configuration (P2)

  • SQLite pool: Add min_connections(2) and acquire_timeout(5s) to pool.rs:78-82
  • Postgres pool: Fix connect_postgres to use max_connections correctly — currently pool_size field is silently ignored (pool.rs:99)
  • Rename/consolidate DbConfig fields: pool_size → remove, use max_connections only

sql! Macro (P2)

  • Replace Box::leak() with LazyLock per call site in postgres variant (lib.rs:102-111):
    macro_rules! sql {
        ($query:expr) => {{
            static REWRITTEN: std::sync::LazyLock<String> =
                std::sync::LazyLock::new(|| $crate::rewrite_placeholders($query));
            REWRITTEN.as_str()
        }};
    }
  • Fix the misleading doc comment that claims LazyLock is already used

Error Consolidation (P2)

  • Merge MemoryError::Sqlx(sqlx::Error) and MemoryError::Db(DbError) into single MemoryError::Db
  • Remove backward-compat aliases: SqliteStore (store/mod.rs:32), SqliteVectorStore (db_vector_store.rs:24)

Edge Upsert Optimization (P2)

  • Replace SELECT+UPDATE/INSERT in insert_edge_typed (graph/store/mod.rs:413-437) with single INSERT ... ON CONFLICT DO UPDATE ... RETURNING id
  • Halves DB round-trips per graph extraction pass

Error Handling (P2)

  • Fix get_vectors (embedding_store.rs:372) — .unwrap_or_default() silently swallows all DB errors. Propagate errors properly.

Acceptance Criteria

  • SQLite pool has min_connections + acquire_timeout
  • Postgres pool respects max_connections config
  • sql! macro on postgres allocates once per call site (add a test)
  • No MemoryError::Sqlx variant
  • No SqliteStore / SqliteVectorStore aliases
  • insert_edge_typed uses single upsert query
  • get_vectors propagates errors
  • All tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureArchitecture improvementsenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions