update alembic/versions/98867adc7088_initial_schema_with_users_sources_.py
Browse files
alembic/versions/98867adc7088_initial_schema_with_users_sources_.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Initial schema with users sources proxies
|
| 2 |
+
|
| 3 |
+
Revision ID: 98867adc7088
|
| 4 |
+
Revises:
|
| 5 |
+
Create Date: 2026-01-11 22:58:56.879192
|
| 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 = '98867adc7088'
|
| 16 |
+
down_revision: Union[str, None] = None
|
| 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('users',
|
| 24 |
+
sa.Column('id', sa.Integer(), nullable=False),
|
| 25 |
+
sa.Column('oauth_provider', sa.String(length=20), nullable=False),
|
| 26 |
+
sa.Column('oauth_id', sa.String(length=100), nullable=False),
|
| 27 |
+
sa.Column('email', sa.String(length=255), nullable=False),
|
| 28 |
+
sa.Column('username', sa.String(length=100), nullable=False),
|
| 29 |
+
sa.Column('avatar_url', sa.Text(), nullable=True),
|
| 30 |
+
sa.Column('role', sa.String(length=20), nullable=False),
|
| 31 |
+
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
| 32 |
+
sa.Column('last_login', sa.DateTime(timezone=True), nullable=True),
|
| 33 |
+
sa.PrimaryKeyConstraint('id')
|
| 34 |
+
)
|
| 35 |
+
op.create_index('idx_oauth_provider_id', 'users', ['oauth_provider', 'oauth_id'], unique=True)
|
| 36 |
+
op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
|
| 37 |
+
op.create_index(op.f('ix_users_oauth_id'), 'users', ['oauth_id'], unique=True)
|
| 38 |
+
op.create_table('proxy_sources',
|
| 39 |
+
sa.Column('id', sa.Integer(), nullable=False),
|
| 40 |
+
sa.Column('user_id', sa.Integer(), nullable=True),
|
| 41 |
+
sa.Column('url', sa.Text(), nullable=False),
|
| 42 |
+
sa.Column('type', sa.String(length=50), nullable=False),
|
| 43 |
+
sa.Column('name', sa.String(length=200), nullable=True),
|
| 44 |
+
sa.Column('description', sa.Text(), nullable=True),
|
| 45 |
+
sa.Column('is_paid', sa.Boolean(), nullable=True),
|
| 46 |
+
sa.Column('enabled', sa.Boolean(), nullable=True),
|
| 47 |
+
sa.Column('validated', sa.Boolean(), nullable=True),
|
| 48 |
+
sa.Column('validation_error', sa.Text(), nullable=True),
|
| 49 |
+
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
| 50 |
+
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
| 51 |
+
sa.Column('last_scraped', sa.DateTime(timezone=True), nullable=True),
|
| 52 |
+
sa.Column('total_scraped', sa.Integer(), nullable=True),
|
| 53 |
+
sa.Column('success_rate', sa.Float(), nullable=True),
|
| 54 |
+
sa.Column('is_admin_source', sa.Boolean(), nullable=True),
|
| 55 |
+
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
|
| 56 |
+
sa.PrimaryKeyConstraint('id')
|
| 57 |
+
)
|
| 58 |
+
op.create_index(op.f('ix_proxy_sources_enabled'), 'proxy_sources', ['enabled'], unique=False)
|
| 59 |
+
op.create_index(op.f('ix_proxy_sources_id'), 'proxy_sources', ['id'], unique=False)
|
| 60 |
+
op.create_index(op.f('ix_proxy_sources_url'), 'proxy_sources', ['url'], unique=True)
|
| 61 |
+
op.create_table('proxies',
|
| 62 |
+
sa.Column('id', sa.Integer(), nullable=False),
|
| 63 |
+
sa.Column('source_id', sa.Integer(), nullable=True),
|
| 64 |
+
sa.Column('url', sa.Text(), nullable=False),
|
| 65 |
+
sa.Column('protocol', sa.String(length=50), nullable=False),
|
| 66 |
+
sa.Column('ip', sa.String(length=50), nullable=True),
|
| 67 |
+
sa.Column('port', sa.Integer(), nullable=True),
|
| 68 |
+
sa.Column('country_code', sa.String(length=2), nullable=True),
|
| 69 |
+
sa.Column('country_name', sa.String(length=100), nullable=True),
|
| 70 |
+
sa.Column('state', sa.String(length=100), nullable=True),
|
| 71 |
+
sa.Column('city', sa.String(length=100), nullable=True),
|
| 72 |
+
sa.Column('latency_ms', sa.Integer(), nullable=True),
|
| 73 |
+
sa.Column('speed_mbps', sa.Float(), nullable=True),
|
| 74 |
+
sa.Column('uptime_percent', sa.Float(), nullable=True),
|
| 75 |
+
sa.Column('anonymity', sa.String(length=20), nullable=True),
|
| 76 |
+
sa.Column('proxy_type', sa.String(length=20), nullable=True),
|
| 77 |
+
sa.Column('can_access_google', sa.Boolean(), nullable=True),
|
| 78 |
+
sa.Column('quality_score', sa.Integer(), nullable=True),
|
| 79 |
+
sa.Column('last_validated', sa.DateTime(timezone=True), nullable=True),
|
| 80 |
+
sa.Column('validation_failures', sa.Integer(), nullable=True),
|
| 81 |
+
sa.Column('is_working', sa.Boolean(), nullable=True),
|
| 82 |
+
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
| 83 |
+
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
| 84 |
+
sa.Column('first_seen', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
| 85 |
+
sa.Column('last_seen', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
| 86 |
+
sa.ForeignKeyConstraint(['source_id'], ['proxy_sources.id'], ondelete='SET NULL'),
|
| 87 |
+
sa.PrimaryKeyConstraint('id')
|
| 88 |
+
)
|
| 89 |
+
op.create_index(op.f('ix_proxies_anonymity'), 'proxies', ['anonymity'], unique=False)
|
| 90 |
+
op.create_index(op.f('ix_proxies_country_code'), 'proxies', ['country_code'], unique=False)
|
| 91 |
+
op.create_index(op.f('ix_proxies_id'), 'proxies', ['id'], unique=False)
|
| 92 |
+
op.create_index(op.f('ix_proxies_is_working'), 'proxies', ['is_working'], unique=False)
|
| 93 |
+
op.create_index(op.f('ix_proxies_latency_ms'), 'proxies', ['latency_ms'], unique=False)
|
| 94 |
+
op.create_index(op.f('ix_proxies_protocol'), 'proxies', ['protocol'], unique=False)
|
| 95 |
+
op.create_index(op.f('ix_proxies_quality_score'), 'proxies', ['quality_score'], unique=False)
|
| 96 |
+
op.create_index(op.f('ix_proxies_url'), 'proxies', ['url'], unique=True)
|
| 97 |
+
op.create_table('validation_history',
|
| 98 |
+
sa.Column('id', sa.Integer(), nullable=False),
|
| 99 |
+
sa.Column('proxy_id', sa.Integer(), nullable=False),
|
| 100 |
+
sa.Column('validated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
| 101 |
+
sa.Column('latency_ms', sa.Integer(), nullable=True),
|
| 102 |
+
sa.Column('anonymity', sa.String(length=20), nullable=True),
|
| 103 |
+
sa.Column('can_access_google', sa.Boolean(), nullable=True),
|
| 104 |
+
sa.Column('success', sa.Boolean(), nullable=False),
|
| 105 |
+
sa.Column('error_message', sa.Text(), nullable=True),
|
| 106 |
+
sa.ForeignKeyConstraint(['proxy_id'], ['proxies.id'], ondelete='CASCADE'),
|
| 107 |
+
sa.PrimaryKeyConstraint('id')
|
| 108 |
+
)
|
| 109 |
+
op.create_index(op.f('ix_validation_history_id'), 'validation_history', ['id'], unique=False)
|
| 110 |
+
op.create_index(op.f('ix_validation_history_proxy_id'), 'validation_history', ['proxy_id'], unique=False)
|
| 111 |
+
op.create_index(op.f('ix_validation_history_validated_at'), 'validation_history', ['validated_at'], unique=False)
|
| 112 |
+
# ### end Alembic commands ###
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def downgrade() -> None:
|
| 116 |
+
# ### commands auto generated by Alembic - please adjust! ###
|
| 117 |
+
op.drop_index(op.f('ix_validation_history_validated_at'), table_name='validation_history')
|
| 118 |
+
op.drop_index(op.f('ix_validation_history_proxy_id'), table_name='validation_history')
|
| 119 |
+
op.drop_index(op.f('ix_validation_history_id'), table_name='validation_history')
|
| 120 |
+
op.drop_table('validation_history')
|
| 121 |
+
op.drop_index(op.f('ix_proxies_url'), table_name='proxies')
|
| 122 |
+
op.drop_index(op.f('ix_proxies_quality_score'), table_name='proxies')
|
| 123 |
+
op.drop_index(op.f('ix_proxies_protocol'), table_name='proxies')
|
| 124 |
+
op.drop_index(op.f('ix_proxies_latency_ms'), table_name='proxies')
|
| 125 |
+
op.drop_index(op.f('ix_proxies_is_working'), table_name='proxies')
|
| 126 |
+
op.drop_index(op.f('ix_proxies_id'), table_name='proxies')
|
| 127 |
+
op.drop_index(op.f('ix_proxies_country_code'), table_name='proxies')
|
| 128 |
+
op.drop_index(op.f('ix_proxies_anonymity'), table_name='proxies')
|
| 129 |
+
op.drop_table('proxies')
|
| 130 |
+
op.drop_index(op.f('ix_proxy_sources_url'), table_name='proxy_sources')
|
| 131 |
+
op.drop_index(op.f('ix_proxy_sources_id'), table_name='proxy_sources')
|
| 132 |
+
op.drop_index(op.f('ix_proxy_sources_enabled'), table_name='proxy_sources')
|
| 133 |
+
op.drop_table('proxy_sources')
|
| 134 |
+
op.drop_index(op.f('ix_users_oauth_id'), table_name='users')
|
| 135 |
+
op.drop_index(op.f('ix_users_id'), table_name='users')
|
| 136 |
+
op.drop_index('idx_oauth_provider_id', table_name='users')
|
| 137 |
+
op.drop_table('users')
|
| 138 |
+
# ### end Alembic commands ###
|