Conversation
added 5 commits
March 29, 2026 14:24
Switch project from SQLite/aiosqlite to PostgreSQL (asyncpg) using SQLAlchemy asyncio and Alembic. Key changes: - Add Alembic config, env and initial migration (001_initial_schema) to manage schema and pgvector extension. - Replace SQLite engine/connection code with an async SQLAlchemy engine (init_engine/get_engine/dispose_engine), ensure_database_exists and run_alembic_upgrade helpers; get_connection now yields AsyncConnection. - Update database-backed repositories and helpers (api_key_repo, installation_repo, global_settings_repo, pr_state, feedback/reaction_collector) to use SQLAlchemy core queries and AsyncConnection; adjust types and upsert/delete semantics accordingly. - Update main startup/shutdown to ensure DB exists, run migrations, initialize engine and dispose on shutdown. - Update health checker to verify database via SQLAlchemy connection instead of aiosqlite. - Add postgres service to docker-compose with healthcheck and adjust Dockerfile to include Alembic files; change default DATABASE_URL to postgres in .env.example and config defaults. - Update pyproject.toml dependencies for asyncpg, sqlalchemy[asyncio], alembic, pgvector and testcontainers postgres; tests adjusted accordingly. This prepares the app for production PostgreSQL usage, schema migrations, and connection pooling.
Update .pre-commit-config.yaml to add stages: [pre-push] for the Python hook (which uses pass_filenames: false and args: [src/]). This makes the hook run during git push as well as other configured stages, preventing issues from being pushed upstream.
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
Migrate storage layer from SQLite/aiosqlite to PostgreSQL/asyncpg with SQLAlchemy Core, Alembic migrations, and pgvector support.
Changes
Database driver: aiosqlite → asyncpg + SQLAlchemy Core (connection pooling, typed schema)
Schema: new src/d1ff/storage/schema.py — single source of truth for all 8 tables
Migrations: Alembic with initial migration + CREATE EXTENSION vector (pgvector ready)
Auto-setup: app creates database if missing, runs migrations on startup
Docker: added pgvector/pgvector:pg17 service, app waits for healthcheck
Tests: testcontainers spins up disposable PostgreSQL per session (411 tests pass)
Breaking changes
DATABASE_URL format changed: postgresql+asyncpg://... instead of sqlite+aiosqlite:///...
aiosqlite dependency removed
Health endpoint field renamed: sqlite → database