Skip to content

Feat/postgresql migration#4

Merged
zeFdon merged 5 commits intomainfrom
feat/postgresql-migration
Mar 29, 2026
Merged

Feat/postgresql migration#4
zeFdon merged 5 commits intomainfrom
feat/postgresql-migration

Conversation

@zeFdon
Copy link
Copy Markdown
Contributor

@zeFdon zeFdon commented Mar 29, 2026

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

tedmenshakov 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.
@zeFdon zeFdon merged commit 158278c into main Mar 29, 2026
1 check passed
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.

1 participant