feat: DB migrations and DB setup - #12
Open
Ankita-Advitot wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a standalone db/ package for the lending POC, containing SQLAlchemy models and Alembic migrations to manage the Postgres schema (including pgvector support) independently of the application layer.
Changes:
- Added SQLAlchemy models for
Case,Document,GoldenRecord,PipelineResult, andValidationResult, plus shared enums and anEncryptedStringcolumn type. - Added a self-contained Alembic setup under
db/migrations/with versioned migrations to create all tables and required enum types/pgvector extension. - Updated local dev infra and dependencies (pgvector-enabled Postgres image, new Python deps).
Reviewed changes
Copilot reviewed 20 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| lending-poc/pyproject.toml | Adds pgvector and cryptography dependencies required by the DB layer. |
| lending-poc/docker-compose.yml | Switches DB image to pgvector-enabled Postgres and changes host port mapping. |
| lending-poc/db/models/case.py | Adds Case model and relationships to other DB entities. |
| lending-poc/db/models/document.py | Adds Document model with doc type enum and extracted fields storage. |
| lending-poc/db/models/golden_record.py | Adds GoldenRecord model including a pgvector embedding column and encrypted fields. |
| lending-poc/db/models/pipeline_result.py | Adds PipelineResult model and review status enum. |
| lending-poc/db/models/validation_result.py | Adds ValidationResult model tied to cases/documents with evidence JSONB. |
| lending-poc/db/models/types.py | Adds EncryptedString TypeDecorator for encrypting sensitive string columns. |
| lending-poc/db/models/enums.py | Defines enums shared across DB schema and pipeline logic (doc/check/decision). |
| lending-poc/db/models/init.py | Exposes DB model imports for convenient registration and access. |
| lending-poc/db/migrations/env.py | Configures Alembic to run against the new db/ package metadata. |
| lending-poc/db/migrations/script.py.mako | Provides the Alembic revision template under the new migrations layout. |
| lending-poc/db/migrations/versions/0001_add_cases.py | Creates cases table and installs vector extension. |
| lending-poc/db/migrations/versions/0002_add_documents.py | Creates documents table and doc_type enum. |
| lending-poc/db/migrations/versions/0003_add_golden_records.py | Creates golden_records table including vector column and encrypted columns. |
| lending-poc/db/migrations/versions/0004_add_pipeline_results.py | Creates pipeline_results table and related enums. |
| lending-poc/db/migrations/versions/0005_add_validation_results.py | Creates validation_results table and related enum. |
| lending-poc/db/database.py | Adds standalone async engine/session setup and Base for the DB package. |
| lending-poc/db/config.py | Adds DB-layer settings (DATABASE_URL, ENCRYPTION_KEY, DEBUG). |
| lending-poc/db/alembic.ini | Points Alembic at the new db/migrations location and adjusts sys.path. |
| lending-poc/db/init.py | Initializes the new db package. |
| lending-poc/.gitignore | Ignores local venv/ directory. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+18
to
+26
| def process_bind_param(self, value: str | None, dialect) -> str | None: | ||
| if value is None: | ||
| return None | ||
| return Fernet(settings.ENCRYPTION_KEY).encrypt(value.encode("utf-8")).decode("utf-8") | ||
|
|
||
| def process_result_value(self, value: str | None, dialect) -> str | None: | ||
| if value is None: | ||
| return None | ||
| return Fernet(settings.ENCRYPTION_KEY).decrypt(value.encode("utf-8")).decode("utf-8") |
Comment on lines
+3
to
+6
| Named `PipelineResult` to match the ERD/table name. This collides with the | ||
| in-memory `app.services.dto.PipelineResult` dataclass — import one or both | ||
| qualified (`from app.models import pipeline_result as pipeline_result_model`) | ||
| in any module that needs both. |
| model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore") | ||
|
|
||
| DEBUG: bool = False | ||
| DATABASE_URL: str = "postgresql+asyncpg://postgres:postgres@localhost:5432/lending_poc" |
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.
Add DB models and standalone migrations layer under db/
Moves the schema (models + Alembic migrations) into a self-contained db/ package . Includes Case, Document, GoldenRecord, PipelineResult, ValidationResult models, the initial migration creating all 5 tables (with pgvector extension), EncryptedString column type, and db/config.py/db/database.py for standalone DB access. docker-compose.yml updated to pgvector/pgvector:pg16; pyproject.toml gets pgvector + cryptography.