feat(db): introduce zeph-db crate with database abstraction layer (Phase 1, SQLite)#2371
Merged
feat(db): introduce zeph-db crate with database abstraction layer (Phase 1, SQLite)#2371
Conversation
…ase 1, SQLite) Adds a new `zeph-db` Layer 0 crate that provides a compile-time database abstraction over sqlx, currently supporting SQLite with PostgreSQL groundwork. Architecture: - `Dialect` trait with `Sqlite` and `Postgres` zero-sized marker types - `DatabaseDriver` trait unifying pool construction, migrations, and transaction semantics; `SqliteDriver` impl in Phase 1 - `ActiveDriver` type alias gates the active backend at compile time - `DbPool`/`DbRow`/`DbTransaction`/`ActiveDialect` derived from `ActiveDriver` - `sql!()` macro for portable placeholder syntax (no-op on SQLite, rewrites `?` to `$N` on PostgreSQL) - `DbConfig` with `write_pool_size = 1` default for SQLite single-writer safety - `redact_url()` strips credentials from connection URLs in error messages - `compile_error!` guard enforces mutual exclusivity of `sqlite`/`postgres` Migrations: - All 50 migrations moved from `zeph-memory/migrations/` to `zeph-db/migrations/sqlite/` - Added `051_scheduler_jobs.sql` and `052_mcp_trust_scores.sql`, replacing inline DDL in `zeph-scheduler` and `zeph-mcp` Consumer crate changes: - `zeph-memory`: `sqlite/` module renamed to `store/`, `sqlite_vector_store.rs` renamed to `db_vector_store.rs`; `SqliteVectorStore` → `DbVectorStore`, `SqliteGraphStore` → `DbGraphStore`; 340+ query strings wrapped in `sql!()` - `zeph-scheduler`: `JobStore::open()` now uses `DbConfig::connect()` for WAL/busy_timeout/foreign_keys; inline DDL removed - `zeph-mcp`, `zeph-orchestration`, `zeph-index`: migrated to `zeph_db::DbPool` and `sql!()` macro - `MemoryError::Sqlite` → `MemoryError::Sqlx` (backend-neutral name) - `SchedulerError::Db` variant added All existing tests pass (7117/7117).
8af9c81 to
8442697
Compare
…mer crates
- Replace datetime('now') with CURRENT_TIMESTAMP (standard SQL, both backends)
- Add Dialect::COLLATE_NOCASE ("COLLATE NOCASE" / "" for SQLite/Postgres)
- Remove Dialect::NOW (superseded by CURRENT_TIMESTAMP)
- Replace all INSERT OR IGNORE with ActiveDialect::INSERT_IGNORE + CONFLICT_NOTHING
across db_vector_store, snapshot, mem_scenes, messages, acp_sessions, graph/store
- Replace COLLATE NOCASE literals with ActiveDialect::COLLATE_NOCASE in graph/store
- Migrate sanitize_fts_query callers to zeph_db::fts; remove local duplicate
- Fix activate_skill_version to use begin_write() instead of pool.begin()
- Remove dead MemoryError::Migration variant
- Add default = ["sqlite"] to zeph-db/Cargo.toml for standalone cargo check
- Fix DatabaseDriver trait: remove run_migrations/begin/begin_write (free fns only)
- Run rustfmt across all modified files
Tests: 7148/7148 passed
This was referenced Mar 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
zeph-dbLayer 0 crate providing compile-time database abstraction over sqlxzeph_db::DbPoolandsql!()instead ofsqlx::SqlitePooldirectlySqliteVectorStore→DbVectorStore,SqliteGraphStore→DbGraphStore,sqlite/module →store/)zeph-db/migrations/sqlite/Architecture
Dialecttrait withSqlite/Postgreszero-sized marker typesDatabaseDrivertrait:SqliteDriverimpl in Phase 1,PostgresDriverskeleton for Phase 2ActiveDrivertype alias gates backend at compile time withcompile_error!mutual exclusivity guardsql!()macro: no-op on SQLite (&'static str), rewrites?to$Non PostgreSQLDbConfigenforceswrite_pool_size = 1for SQLite to preventSQLITE_BUSYredact_url()strips credentials from connection URLs in error pathsSpec
Full architectural spec (reviewed by critic, perf, and security agents):
.local/specs/database-abstraction/spec.mdTest plan
cargo check --features full— cleancargo +nightly fmt --check— cleancargo clippy --workspace --features full -- -D warnings— cleancargo nextest run --workspace --features full --lib --bins— 7117/7117 passed--migrate-config, vault integration) — separate PR