← Back to Pull requests

feat: Replace PostgreSQL with embedded SQLite database #318

Closed
unknown closed this pull request without merging on Aug 06, 2026 13:23 UTC
View on GitHub
unknown unknown commented on Jul 31, 2026 21:00 UTC
Author

Description

Replace the external PostgreSQL dependency with Python's built-in sqlite3 module. The backend no longer requires a separate database server — benchmark data is stored in a local SQLite file
(PLANNER_DB_PATH, default data/planner.db). This eliminates operational complexity and enables releasing the backend as a self-contained Python wheel.

### What changed

New db.py connection factory:
- create_connection(db_path) — creates a connection with WAL mode, busy timeout, and auto schema initialization
- Per-instance pattern: BenchmarkRepository owns its connection (no global singleton)
- find_project_root() resolves the default DB path relative to the project root, not cwd

BenchmarkRepository API improvements (inspired by amito/llm-d-planner#3):
- from_files(json_paths) classmethod — construct a ready-to-use repository from JSON files
- replace_benchmarks(source, benchmarks) — delete-by-source + insert (used by Model Catalog sync)
- load_benchmarks(benchmarks, source, confidence_level) — append mode insert
- get_stats() / reset() — database management via public API

SQL dialect migration:
- %s → ?, %(name)s → :name, ANY(%s) → IN (?, ?, ...)
- TRUNCATE CASCADE → DELETE FROM, execute_batch → executemany
- COUNT(DISTINCT (col1, col2)) → subquery
- Window functions and ON CONFLICT DO NOTHING — same syntax, supported by SQLite

Model Catalog sync:
- sync_model_catalog() takes a BenchmarkRepository instead of a raw connection
- Uses repo.replace_benchmarks("model_catalog", rows) instead of raw DELETE + executemany
- Duplicate _INSERT_COLUMNS / _INSERT_QUERY removed (~60 lines)
- confidence_level explicitly set to "benchmarked" for catalog data

Infrastructure:
- make db-reset uses DELETE FROM (safe while backend is running — no file replacement)
- make db-stop, make db-convert-pgdump, make test-db removed
- PLANNER_BENCHMARK_SOURCE default renamed "postgresql" → "database"
- Docker Compose: postgres service removed
- Kubernetes: postgres.yaml and db-init-job.yaml deleted, PVC added at /app/db for the database file (avoids shadowing the image's data/ directory)
- postgresql-client removed from Dockerfile
- psycopg2-binary removed from pyproject.toml

Tests:
- @pytest.mark.database merged into unit tests (no external DB needed)
- conftest.py uses BenchmarkRepository.from_files() with a temp SQLite file
- Mock targets updated for per-instance pattern (no singleton management)
- test_postgresql_integration.py renamed to test_benchmark_repository.py

Known limitation: Single-instance only. If multi-replica with shared state is needed later, an external DB backend can be added — the DB surface area is contained in knowledge_base/.

### Key behavioral change

make db-reset now clears data in-place (DELETE FROM) instead of deleting and recreating the file. This means make db-reset && make db-load-guidellm works while the backend is running —
the backend's connection remains valid because the file isn't replaced.

## How Has This Been Tested?

- 538 unit tests passing (make test-unit)
- 3 integration scenario tests passing (test_recommendation_workflow.py — end-to-end recommendation generation with BLIS and GuideLLM benchmark data)
- make format / make lint / make typecheck all clean
- Database workflow verified: make db-reset && make db-load-blis && make db-query-traffic && make db-query-models
- Zero remaining references: grep -rn 'psycopg2\|DATABASE_URL' src/ scripts/ tests/ --include='
.py' returns no hits
- Manual testing: backend + UI started locally, recommendation requests submitted and verified
- OpenShift deployment tested: deployed to ephemeral namespace, verified Configuration tab, Define Use Case tab, and recommendation generation all work
- Model Catalog sync path verified: PLANNER_BENCHMARK_SOURCE=model_catalog with live cluster sync

## Merge criteria:

- [x] The commits are squashed in a cohesive manner and have meaningful messages.
- [x] Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
- [x] The developer has manually tested the changes and verified that the changes work

Diff: 566 lines (+424 / -142) across 7 files Reviewer: amito Review duration: 8183m
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.55) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.55 · 566 lines diff across 7 files
0.55
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.379
Shallow Review Depth shallow_review_depth
0.289
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #318"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 54.7% (MEDIUM) · Higher = larger blast radius
54.7%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 21.6% · Safe to merge
21.6%