75 lines
3 KiB
Python
75 lines
3 KiB
Python
|
|
"""separate job orchestration from article content
|
||
|
|
|
||
|
|
Revision ID: 0006
|
||
|
|
Revises: 0005
|
||
|
|
Create Date: 2026-03-29
|
||
|
|
|
||
|
|
"""
|
||
|
|
from typing import Sequence, Union
|
||
|
|
|
||
|
|
import sqlalchemy as sa
|
||
|
|
from alembic import op
|
||
|
|
from sqlalchemy.dialects import postgresql
|
||
|
|
|
||
|
|
revision: str = "0006"
|
||
|
|
down_revision: Union[str, None] = "0005"
|
||
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
||
|
|
depends_on: Union[str, Sequence[str], None] = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
# Make article content fields nullable — they are now filled in step-by-step
|
||
|
|
op.alter_column("translated_articles", "source_title", nullable=True)
|
||
|
|
op.alter_column("translated_articles", "source_body", nullable=True)
|
||
|
|
op.alter_column("translated_articles", "target_title", nullable=True)
|
||
|
|
op.alter_column("translated_articles", "target_body", nullable=True)
|
||
|
|
|
||
|
|
# Add source_body_pos to translated_articles
|
||
|
|
op.add_column(
|
||
|
|
"translated_articles",
|
||
|
|
sa.Column("source_body_pos", postgresql.JSONB(), nullable=True),
|
||
|
|
)
|
||
|
|
|
||
|
|
# Add FK from jobs to the article they produce
|
||
|
|
op.add_column(
|
||
|
|
"jobs",
|
||
|
|
sa.Column(
|
||
|
|
"translated_article_id",
|
||
|
|
postgresql.UUID(as_uuid=True),
|
||
|
|
sa.ForeignKey("translated_articles.id"),
|
||
|
|
nullable=True,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
|
||
|
|
# Drop content columns that now live on translated_articles
|
||
|
|
op.drop_column("jobs", "source_language")
|
||
|
|
op.drop_column("jobs", "target_language")
|
||
|
|
op.drop_column("jobs", "complexity_level")
|
||
|
|
op.drop_column("jobs", "input_summary")
|
||
|
|
op.drop_column("jobs", "generated_text")
|
||
|
|
op.drop_column("jobs", "translated_text")
|
||
|
|
op.drop_column("jobs", "audio_url")
|
||
|
|
op.drop_column("jobs", "source_pos_data")
|
||
|
|
op.drop_column("jobs", "target_pos_data")
|
||
|
|
op.drop_column("jobs", "audio_transcript")
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
op.add_column("jobs", sa.Column("audio_transcript", postgresql.JSONB(), nullable=True))
|
||
|
|
op.add_column("jobs", sa.Column("target_pos_data", postgresql.JSONB(), nullable=True))
|
||
|
|
op.add_column("jobs", sa.Column("source_pos_data", postgresql.JSONB(), nullable=True))
|
||
|
|
op.add_column("jobs", sa.Column("audio_url", sa.Text(), nullable=True))
|
||
|
|
op.add_column("jobs", sa.Column("translated_text", sa.Text(), nullable=True))
|
||
|
|
op.add_column("jobs", sa.Column("generated_text", sa.Text(), nullable=True))
|
||
|
|
op.add_column("jobs", sa.Column("input_summary", sa.Text(), nullable=True))
|
||
|
|
op.add_column("jobs", sa.Column("complexity_level", sa.String(5), nullable=False, server_default="B1"))
|
||
|
|
op.add_column("jobs", sa.Column("target_language", sa.String(10), nullable=False, server_default="fr"))
|
||
|
|
op.add_column("jobs", sa.Column("source_language", sa.String(10), nullable=False, server_default="en"))
|
||
|
|
|
||
|
|
op.drop_column("jobs", "translated_article_id")
|
||
|
|
|
||
|
|
op.alter_column("translated_articles", "target_body", nullable=False)
|
||
|
|
op.alter_column("translated_articles", "target_title", nullable=False)
|
||
|
|
op.alter_column("translated_articles", "source_body", nullable=False)
|
||
|
|
op.alter_column("translated_articles", "source_title", nullable=False)
|