update alembic/versions/9f610160ba2b_add_scraping_sessions_and_background_.py
Browse files
alembic/versions/9f610160ba2b_add_scraping_sessions_and_background_.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add scraping sessions and background tasks tables
|
| 2 |
+
|
| 3 |
+
Revision ID: 9f610160ba2b
|
| 4 |
+
Revises: 3ee140dfb02a
|
| 5 |
+
Create Date: 2026-01-16 04:36:01.237349
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from typing import Sequence, Union
|
| 9 |
+
|
| 10 |
+
from alembic import op
|
| 11 |
+
import sqlalchemy as sa
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# revision identifiers, used by Alembic.
|
| 15 |
+
revision: str = '9f610160ba2b'
|
| 16 |
+
down_revision: Union[str, None] = '3ee140dfb02a'
|
| 17 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 18 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def upgrade() -> None:
|
| 22 |
+
# ### commands auto generated by Alembic - please adjust! ###
|
| 23 |
+
op.create_table('background_tasks',
|
| 24 |
+
sa.Column('id', sa.Integer(), nullable=False),
|
| 25 |
+
sa.Column('task_type', sa.String(length=100), nullable=False),
|
| 26 |
+
sa.Column('task_data', sa.JSON(), nullable=False),
|
| 27 |
+
sa.Column('status', sa.String(length=20), nullable=False),
|
| 28 |
+
sa.Column('result', sa.JSON(), nullable=True),
|
| 29 |
+
sa.Column('error_message', sa.Text(), nullable=True),
|
| 30 |
+
sa.Column('retry_count', sa.Integer(), nullable=True),
|
| 31 |
+
sa.Column('max_retries', sa.Integer(), nullable=True),
|
| 32 |
+
sa.Column('scheduled_for', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
| 33 |
+
sa.Column('started_at', sa.DateTime(timezone=True), nullable=True),
|
| 34 |
+
sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
|
| 35 |
+
sa.PrimaryKeyConstraint('id')
|
| 36 |
+
)
|
| 37 |
+
op.create_index('idx_background_task_status_scheduled', 'background_tasks', ['status', 'scheduled_for'], unique=False)
|
| 38 |
+
op.create_index(op.f('ix_background_tasks_id'), 'background_tasks', ['id'], unique=False)
|
| 39 |
+
op.create_index(op.f('ix_background_tasks_scheduled_for'), 'background_tasks', ['scheduled_for'], unique=False)
|
| 40 |
+
op.create_index(op.f('ix_background_tasks_status'), 'background_tasks', ['status'], unique=False)
|
| 41 |
+
op.create_index(op.f('ix_background_tasks_task_type'), 'background_tasks', ['task_type'], unique=False)
|
| 42 |
+
op.create_table('scraping_sessions',
|
| 43 |
+
sa.Column('id', sa.Integer(), nullable=False),
|
| 44 |
+
sa.Column('source_id', sa.Integer(), nullable=False),
|
| 45 |
+
sa.Column('scraping_type', sa.String(length=50), nullable=False),
|
| 46 |
+
sa.Column('status', sa.String(length=20), nullable=False),
|
| 47 |
+
sa.Column('proxies_found', sa.Integer(), nullable=True),
|
| 48 |
+
sa.Column('proxies_valid', sa.Integer(), nullable=True),
|
| 49 |
+
sa.Column('config', sa.JSON(), nullable=True),
|
| 50 |
+
sa.Column('error_message', sa.Text(), nullable=True),
|
| 51 |
+
sa.Column('initiated_by', sa.Integer(), nullable=True),
|
| 52 |
+
sa.Column('started_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
| 53 |
+
sa.Column('finished_at', sa.DateTime(timezone=True), nullable=True),
|
| 54 |
+
sa.ForeignKeyConstraint(['initiated_by'], ['users.id'], ondelete='SET NULL'),
|
| 55 |
+
sa.ForeignKeyConstraint(['source_id'], ['proxy_sources.id'], ondelete='CASCADE'),
|
| 56 |
+
sa.PrimaryKeyConstraint('id')
|
| 57 |
+
)
|
| 58 |
+
op.create_index('idx_scraping_session_status_source', 'scraping_sessions', ['status', 'source_id'], unique=False)
|
| 59 |
+
op.create_index(op.f('ix_scraping_sessions_id'), 'scraping_sessions', ['id'], unique=False)
|
| 60 |
+
op.create_index(op.f('ix_scraping_sessions_initiated_by'), 'scraping_sessions', ['initiated_by'], unique=False)
|
| 61 |
+
op.create_index(op.f('ix_scraping_sessions_source_id'), 'scraping_sessions', ['source_id'], unique=False)
|
| 62 |
+
op.create_index(op.f('ix_scraping_sessions_started_at'), 'scraping_sessions', ['started_at'], unique=False)
|
| 63 |
+
op.create_index(op.f('ix_scraping_sessions_status'), 'scraping_sessions', ['status'], unique=False)
|
| 64 |
+
# ### end Alembic commands ###
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def downgrade() -> None:
|
| 68 |
+
# ### commands auto generated by Alembic - please adjust! ###
|
| 69 |
+
op.drop_index(op.f('ix_scraping_sessions_status'), table_name='scraping_sessions')
|
| 70 |
+
op.drop_index(op.f('ix_scraping_sessions_started_at'), table_name='scraping_sessions')
|
| 71 |
+
op.drop_index(op.f('ix_scraping_sessions_source_id'), table_name='scraping_sessions')
|
| 72 |
+
op.drop_index(op.f('ix_scraping_sessions_initiated_by'), table_name='scraping_sessions')
|
| 73 |
+
op.drop_index(op.f('ix_scraping_sessions_id'), table_name='scraping_sessions')
|
| 74 |
+
op.drop_index('idx_scraping_session_status_source', table_name='scraping_sessions')
|
| 75 |
+
op.drop_table('scraping_sessions')
|
| 76 |
+
op.drop_index(op.f('ix_background_tasks_task_type'), table_name='background_tasks')
|
| 77 |
+
op.drop_index(op.f('ix_background_tasks_status'), table_name='background_tasks')
|
| 78 |
+
op.drop_index(op.f('ix_background_tasks_scheduled_for'), table_name='background_tasks')
|
| 79 |
+
op.drop_index(op.f('ix_background_tasks_id'), table_name='background_tasks')
|
| 80 |
+
op.drop_index('idx_background_task_status_scheduled', table_name='background_tasks')
|
| 81 |
+
op.drop_table('background_tasks')
|
| 82 |
+
# ### end Alembic commands ###
|