generated from john/python-template
4.1 KiB
4.1 KiB
Implementation Plan (Version 3)
Goal
Replace the current v2 SQLModel schema with the approved v3 schema and make sure every database operation works through the existing async SQLAlchemy/SQLModel session layer.
Use a fresh database. There will be no migrations, data conversion, legacy compatibility shims, or parallel v2/v3 code paths.
Current Project Impact
src/transcription/db/models.pydefines the SQLModel tables. It must be updated to match the approved v3 schema (Document,Person,DocumentPerson,Source,Job,JobSource).- The v3 target adds input provenance fields (
prompt_name,prompt_hash,system_prompt,user_prompt,temperature,top_p) and full output payloads (raw_api_response,ai_metadata) toJobSource. - The v3 target adds image asset verification fields (
file_hash,file_size_bytes) toSource. - Database operations must utilize the
JSONBCompatdecorator to remain database-agnostic (SQLite for local development/testing and PostgreSQL for production). - Async CRUD lives in
DocumentService,JobService,TranscriptionService, and upload helpers. Their queries and relationship loading must be updated for v3 fields.
Implementation
1. Update the Schema and Domain Models
- Replace the models in
src/transcription/db/models.pywith the approved v3 tables, enums, relationships, foreign keys, constraints, and indexes. - Ensure all JSON fields use
JSONBCompatfor dialect portability across SQLite and PostgreSQL. - Keep
SQLModel.metadata.create_all()as the schema bootstrap for fresh databases. - Delete
_ensure_sqlite_compat_columns()and all legacy schema patching fromsrc/transcription/db/operations.py. - Keep the Python models and
docs/schema_v3.mdperfectly synchronized.
2. Update Data Services and Async Worker Layer
- Update
JobServiceand worker tasks (worker.py) to construct and save page-level input prompt fields (prompt_name,prompt_hash,system_prompt,user_prompt,temperature,top_p) directly ontoJobSourcerecords upon execution. - Update
TranscriptionServiceand provider adapters to store the complete unedited API REST response dictionary intojob_source.raw_api_responsealongside operational metrics injob_source.ai_metadata. - Update upload handlers to calculate and store file metadata (
file_hashvia SHA-256,file_size_bytes) onSourcerecords during file ingestion.
3. Update Integration Tests and Mock AI Providers
- Update mock provider fixtures in test suites to return realistic complete API response envelopes.
- Verify test coverage for
JSONBCompatfield writes and reads under SQLite in-memory test databases. - Add assertions in async workflow tests to verify page-level prompt provenance and failure isolation on
JobSource.
4. Update the UI for the v3 Schema
- Review the UI components and views displaying document, job, person, and source data so they reference v3 schema properties instead of v2 relationships.
- Ensure the UI correctly renders
COALESCE(revised_text, raw_transcription)for page viewing and inline editing. - Ensure the "Retry Failed Pages" UI action spawns targeted jobs correctly using page-level
JobSourcefailure states. - Consider the guidance in
docs/ui_style_guide.mdwhen making UI changes so updated views remain consistent with the project’s visual conventions.
Done When
- A fresh database is created directly from the v3 SQLModel metadata.
- Full input/output provenance is captured on
JobSourcefor every AI execution task. - The focused tests and full test suite pass on both SQLite and PostgreSQL backends.
Out of Scope
- Database migrations or preservation of v2 data
- Legacy compatibility code
- UI redesign, batch orchestration, worker concurrency, deployment, and operational runbooks
Related Local References
- System Overview
- System Design Intent
- Transcription Methodology
- System Architecture
- System Requirements
- Data model
- Error Handling Policy
- Implementation Plan (this document)