Files
AlphaPulse/backend/alembic/versions/20261101_f60123456789_backfill.py
T
eezd b45981ec30
Development CI / check-and-build (push) Successful in 2m44s
GitHub Git mirror / mirror (push) Successful in 6s
Development CI / deploy-development (push) Failing after 7s
feat: add historical news AI backfill and visible task queue
Freeze date-range previews and model settings, track per-news progress and downstream targets, and share completion-driven scheduling with realtime analysis.

Prevent overlapping retries for the same news, retain batch queue associations, and refresh selected details with session-safe pagination.
2026-11-01 14:47:54 +08:00

33 lines
1.8 KiB
Python

"""Normalize historical items and track the batch's downstream targets."""
from alembic import op
import sqlalchemy as sa
revision = 'f60123456789'
down_revision = 'e5f701234567'
branch_labels = depends_on = None
def upgrade():
op.create_table('news_ai_reprocess_items',
sa.Column('id', sa.BigInteger(), primary_key=True),
sa.Column('job_id', sa.BigInteger(), sa.ForeignKey('news_ai_reprocess_jobs.id'), nullable=False, index=True),
sa.Column('news_id', sa.BigInteger(), sa.ForeignKey('news_items.id'), nullable=False, index=True),
sa.Column('content_hash', sa.String(64), nullable=False),
sa.Column('mode', sa.String(16), nullable=False),
sa.Column('state', sa.String(16), nullable=False, index=True), sa.Column('error', sa.Text()),
sa.Column('started_at', sa.DateTime(timezone=True)), sa.Column('finished_at', sa.DateTime(timezone=True)),
sa.UniqueConstraint('job_id', 'news_id'))
op.create_table('news_ai_reprocess_targets',
sa.Column('id', sa.BigInteger(), primary_key=True),
sa.Column('job_id', sa.BigInteger(), sa.ForeignKey('news_ai_reprocess_jobs.id'), nullable=False, index=True),
sa.Column('kind', sa.String(16), nullable=False), sa.Column('object_id', sa.BigInteger(), nullable=False),
sa.Column('revision', sa.Integer(), nullable=False), sa.UniqueConstraint('job_id', 'kind', 'object_id'))
op.execute("""INSERT INTO news_ai_reprocess_items(job_id,news_id,content_hash,mode,state)
SELECT j.id,(i->>'id')::bigint,i->>'hash','legacy',i->>'state'
FROM news_ai_reprocess_jobs j, jsonb_array_elements(j.items) i
JOIN news_items n ON n.id=(i->>'id')::bigint ON CONFLICT DO NOTHING""")
def downgrade():
op.drop_table('news_ai_reprocess_targets')
op.drop_table('news_ai_reprocess_items')