Skip to content

feat: DB migrations and DB setup - #12

Open
Ankita-Advitot wants to merge 2 commits into
lending_poc/mainfrom
feature/db-migrations
Open

feat: DB migrations and DB setup#12
Ankita-Advitot wants to merge 2 commits into
lending_poc/mainfrom
feature/db-migrations

Conversation

@Ankita-Advitot

Copy link
Copy Markdown
Contributor

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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, and ValidationResult, plus shared enums and an EncryptedString column 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.
Comment thread lending-poc/db/config.py
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"
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.

2 participants