Skip to content

[FEAT] Adds the database configuration and schema management.#25

Draft
maralbahari wants to merge 7 commits into
vllm-project:mainfrom
EmbeddedLLM:database-config
Draft

[FEAT] Adds the database configuration and schema management.#25
maralbahari wants to merge 7 commits into
vllm-project:mainfrom
EmbeddedLLM:database-config

Conversation

@maralbahari
Copy link
Copy Markdown
Collaborator

@maralbahari maralbahari commented May 12, 2026

Summary

Adds the database configuration, schema management, and CRUD layer for the three-table persistence schema used by the Responses and Conversation APIs.

What's in this PR

  • RuntimeConfig: single struct deriving both clap::Parser and validator::Validate; CLI args and field validation in one place with no GatewayOpts duplication
  • DbPool via sqlx::Any: single pool type that works with both SQLite and PostgreSQL at runtime; no per-dialect code duplication
  • Three-table schema: conversations, items, responses tables matching the Python schema exactly; managed via sqlx migrations in migrations/0001_initial.sql
  • SchemaManager: runs migrations on startup; respects AA_DB_SCHEMA_READY env var so worker processes skip DDL; uses sqlx's built-in migration lock replacing Python's PostgreSQL advisory lock
  • CRUD operations : database/conversation.rs, database/item.rs, database/response.rs.

Test Plan

Note: src/bin/ does not exist in this branch. To verify schema initialisation, create it temporarily:

mkdir -p src/bin

Then add src/bin/init_db.rs:

use agentic_api::database::db::create_pool;
use agentic_api::database::schema::SchemaManager;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let db_url = std::env::args().nth(1)
        .unwrap_or_else(|| "sqlite://./agentic_api.db".to_string());
    let pool = create_pool(&db_url).await?;
    SchemaManager::new(&pool).ensure_ready().await?;
    println!("Schema ready.");
    Ok(())
}
# Schema verification
cargo run --bin init_db
cargo run --bin init_db -- "sqlite:///path/to/db"

# Check tables
sqlite3 agentic_api.db "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"
# Expected: _sqlx_migrations, conversations, items, responses

# Full build must pass
cargo build

Test Results

Both SQLite paths verified — default and explicit
==> Test 1: default DB (no argument)...
     Running `target/debug/init_db`
Connecting to: sqlite://./agentic_api.db
Running schema migrations...
Schema ready. Tables created successfully.

==> Tables in agentic_api.db...
_sqlx_migrations
conversations
items
responses

==> Test 2: explicit DB path...
     Running `target/debug/init_db 'sqlite:///home/tunjitan/ellmm/test_agentic_api.db'`
Connecting to: sqlite:///home/tunjitan/ellmm/test_agentic_api.db
Running schema migrations...
Schema ready. Tables created successfully.

==> Tables in test_agentic_api.db...
_sqlx_migrations
conversations
items
responses

leseb and others added 2 commits May 11, 2026 20:45
Replaces the Python gateway stub with a full Rust implementation
using axum, reqwest, and tokio. Supports both streaming (SSE) and
non-streaming proxy modes, hop-by-hop header filtering, API key
injection, and comprehensive error mapping (502/504).

Includes 11 tests covering passthrough, auth, streaming, error
propagation, mid-stream failure, connection errors, and timeouts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
- Add RuntimeConfig with clap + validator derives (single-struct CLI/config)
- Add DbPool using sqlx Any driver (SQLite + PostgreSQL support)
- Add three-table schema: conversations, items, responses
- Add CRUD operations for all three tables
- Add SchemaManager with sqlx migrations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: maral <maralbahari.98@gmail.com>
Signed-off-by: maral <maralbahari.98@gmail.com>
@maralbahari maralbahari marked this pull request as draft May 12, 2026 15:02
maralbahari and others added 4 commits May 13, 2026 02:45
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: maral <maralbahari.98@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: maral <maralbahari.98@gmail.com>
…and conversation item count query

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: maral <maralbahari.98@gmail.com>
Replace global OnceLock with Arc<DbPool>, consolidate get_or_create_conversation
with UPSERT to eliminate redundant queries. Remove unused CRUD helpers.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: maral <maralbahari.98@gmail.com>
@@ -0,0 +1,31 @@
CREATE TABLE IF NOT EXISTS conversations (
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conversations can be a bit of a lot. Maybe we should start off narrow with just the rust server for responses models and use ogx as an MVP? That way we get all of the API surface area without having to maintain that implementation right away? We can discuss tomorrow of course.

CC @leseb @jiahuei

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franciscojavierarceo yes I agree we can focus on responses first. less complexity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants