-
Notifications
You must be signed in to change notification settings - Fork 7
Evaluation: Migration Cleanups #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa75414
updated indexes
AkhileshNegi 237227b
moving to JSONB
AkhileshNegi 9585979
moving to JSONB
AkhileshNegi 284cac4
formatting fixes
AkhileshNegi ff3b4c1
cleanups
AkhileshNegi d854bbe
on delete null
AkhileshNegi 7181054
cleanup comments
AkhileshNegi 68fe7b8
updated models
AkhileshNegi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
backend/app/alembic/versions/633e69806207_evaluation_update_constraints.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| """evaluation update constraints | ||
|
|
||
| Revision ID: 633e69806207 | ||
| Revises: 6fe772038a5a | ||
| Create Date: 2025-11-13 11:36:16.484694 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "633e69806207" | ||
| down_revision = "6fe772038a5a" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.alter_column( | ||
| "evaluation_run", | ||
| "config", | ||
| existing_type=postgresql.JSON(astext_type=sa.Text()), | ||
| type_=postgresql.JSONB(astext_type=sa.Text()), | ||
| existing_nullable=False, | ||
| ) | ||
| op.alter_column( | ||
| "evaluation_run", | ||
| "score", | ||
| existing_type=postgresql.JSON(astext_type=sa.Text()), | ||
| type_=postgresql.JSONB(astext_type=sa.Text()), | ||
AkhileshNegi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| existing_nullable=True, | ||
| ) | ||
| # Remove SET NULL behavior from evaluation_run batch_job foreign keys | ||
| # This ensures evaluation runs fail if their batch job is deleted (maintain referential integrity) | ||
| op.drop_constraint( | ||
| "fk_evaluation_run_embedding_batch_job_id", "evaluation_run", type_="foreignkey" | ||
| ) | ||
| op.drop_constraint( | ||
| "evaluation_run_batch_job_id_fkey", "evaluation_run", type_="foreignkey" | ||
| ) | ||
| op.drop_constraint( | ||
| "openai_conversation_organization_id_fkey1", | ||
| "openai_conversation", | ||
| type_="foreignkey", | ||
| ) | ||
| op.drop_constraint( | ||
| "openai_conversation_project_id_fkey1", | ||
| "openai_conversation", | ||
| type_="foreignkey", | ||
| ) | ||
| op.create_foreign_key( | ||
| "evaluation_run_batch_job_id_fkey", | ||
| "evaluation_run", | ||
| "batch_job", | ||
| ["batch_job_id"], | ||
| ["id"], | ||
| ondelete="SET NULL", | ||
| ) | ||
| op.create_foreign_key( | ||
| "fk_evaluation_run_embedding_batch_job_id", | ||
| "evaluation_run", | ||
| "batch_job", | ||
| ["embedding_batch_job_id"], | ||
| ["id"], | ||
| ondelete="SET NULL", | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| op.alter_column( | ||
| "evaluation_run", | ||
| "score", | ||
| existing_type=postgresql.JSONB(astext_type=sa.Text()), | ||
| type_=postgresql.JSON(astext_type=sa.Text()), | ||
| existing_nullable=True, | ||
| ) | ||
| op.alter_column( | ||
| "evaluation_run", | ||
| "config", | ||
| existing_type=postgresql.JSONB(astext_type=sa.Text()), | ||
| type_=postgresql.JSON(astext_type=sa.Text()), | ||
| existing_nullable=False, | ||
| ) | ||
| # Restore SET NULL behavior to evaluation_run batch_job foreign keys | ||
| op.drop_constraint( | ||
| "fk_evaluation_run_embedding_batch_job_id", "evaluation_run", type_="foreignkey" | ||
| ) | ||
| op.drop_constraint( | ||
| "evaluation_run_batch_job_id_fkey", "evaluation_run", type_="foreignkey" | ||
| ) | ||
| op.create_foreign_key( | ||
| "evaluation_run_batch_job_id_fkey", | ||
| "evaluation_run", | ||
| "batch_job", | ||
| ["batch_job_id"], | ||
| ["id"], | ||
| ondelete="SET NULL", | ||
| ) | ||
| op.create_foreign_key( | ||
| "fk_evaluation_run_embedding_batch_job_id", | ||
| "evaluation_run", | ||
| "batch_job", | ||
| ["embedding_batch_job_id"], | ||
| ["id"], | ||
| ondelete="SET NULL", | ||
| ) | ||
| op.create_foreign_key( | ||
| "openai_conversation_organization_id_fkey1", | ||
| "openai_conversation", | ||
| "organization", | ||
| ["organization_id"], | ||
| ["id"], | ||
| ) | ||
| op.create_foreign_key( | ||
| "openai_conversation_project_id_fkey1", | ||
| "openai_conversation", | ||
| "project", | ||
| ["project_id"], | ||
| ["id"], | ||
| ) | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| from datetime import datetime | ||
| from typing import TYPE_CHECKING, Any, Optional | ||
|
|
||
| from sqlalchemy import Column | ||
| from sqlalchemy import Column, Index, Text | ||
| from sqlalchemy.dialects.postgresql import JSONB | ||
| from sqlmodel import Field, Relationship, SQLModel | ||
|
|
||
|
|
@@ -16,55 +16,81 @@ class BatchJob(SQLModel, table=True): | |
| """Batch job table for tracking async LLM batch operations.""" | ||
|
|
||
| __tablename__ = "batch_job" | ||
| __table_args__ = ( | ||
| Index("idx_batch_job_status_org", "provider_status", "organization_id"), | ||
AkhileshNegi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Index("idx_batch_job_status_project", "provider_status", "project_id"), | ||
| ) | ||
|
|
||
| id: int | None = Field(default=None, primary_key=True) | ||
|
|
||
| # Provider and job type | ||
| provider: str = Field(description="LLM provider name (e.g., 'openai', 'anthropic')") | ||
| provider: str = Field( | ||
| description="LLM provider name (e.g., 'openai', 'anthropic')", | ||
| ) | ||
| job_type: str = Field( | ||
| description="Type of batch job (e.g., 'evaluation', 'classification', 'embedding')" | ||
| index=True, | ||
| description=( | ||
| "Type of batch job (e.g., 'evaluation', 'classification', 'embedding')" | ||
| ), | ||
| ) | ||
|
|
||
| # Batch configuration - stores all provider-specific config | ||
| config: dict[str, Any] = Field( | ||
| default_factory=dict, | ||
| sa_column=Column(JSONB()), | ||
| description="Complete batch configuration including model, temperature, instructions, tools, etc.", | ||
| sa_column=Column(JSONB, nullable=False), | ||
| description=( | ||
| "Complete batch configuration including model, temperature, " | ||
| "instructions, tools, etc." | ||
| ), | ||
| ) | ||
|
|
||
| # Provider-specific batch tracking | ||
| provider_batch_id: str | None = Field( | ||
| default=None, description="Provider's batch job ID (e.g., OpenAI batch_id)" | ||
| default=None, | ||
| description="Provider's batch job ID (e.g., OpenAI batch_id)", | ||
| ) | ||
| provider_file_id: str | None = Field( | ||
| default=None, description="Provider's input file ID" | ||
| default=None, | ||
| description="Provider's input file ID", | ||
| ) | ||
| provider_output_file_id: str | None = Field( | ||
| default=None, description="Provider's output file ID" | ||
| default=None, | ||
| description="Provider's output file ID", | ||
| ) | ||
|
|
||
| # Provider status tracking | ||
| provider_status: str | None = Field( | ||
AkhileshNegi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| default=None, | ||
| description="Provider-specific status (e.g., OpenAI: validating, in_progress, finalizing, completed, failed, expired, cancelling, cancelled)", | ||
| description=( | ||
| "Provider-specific status (e.g., OpenAI: validating, in_progress, " | ||
| "finalizing, completed, failed, expired, cancelling, cancelled)" | ||
| ), | ||
| ) | ||
|
|
||
| # Raw results (before parent-specific processing) | ||
| raw_output_url: str | None = Field( | ||
| default=None, description="S3 URL of raw batch output file" | ||
| default=None, | ||
| description="S3 URL of raw batch output file", | ||
| ) | ||
| total_items: int = Field( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all the Fields, You don’t need to use sa_column here. SQLModel already infers the SQLAlchemy column from the type annotation + Field() metadata.
|
||
| default=0, description="Total number of items in the batch" | ||
| default=0, | ||
| description="Total number of items in the batch", | ||
| ) | ||
|
|
||
| # Error handling | ||
| error_message: str | None = Field( | ||
| default=None, description="Error message if batch failed" | ||
| default=None, | ||
| sa_column=Column(Text, nullable=True), | ||
| description="Error message if batch failed", | ||
| ) | ||
|
|
||
| # Foreign keys | ||
| organization_id: int = Field(foreign_key="organization.id") | ||
| project_id: int = Field(foreign_key="project.id") | ||
| organization_id: int = Field( | ||
| foreign_key="organization.id", nullable=False, ondelete="CASCADE", index=True | ||
| ) | ||
| project_id: int = Field( | ||
| foreign_key="project.id", nullable=False, ondelete="CASCADE", index=True | ||
| ) | ||
|
|
||
| # Timestamps | ||
| inserted_at: datetime = Field( | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.