170 lines
8.0 KiB
Python
170 lines
8.0 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 054c116946ac
|
|
Revises:
|
|
Create Date: 2025-11-22 00:37:30.417108
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '054c116946ac'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table('users',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('username', sa.String(length=64), nullable=False),
|
|
sa.Column('email', sa.String(length=120), nullable=False),
|
|
sa.Column('password_hash', sa.String(length=256), nullable=True),
|
|
sa.Column('role', sa.String(length=20), nullable=True),
|
|
sa.Column('status', sa.String(length=20), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('pt_site', sa.String(length=100), nullable=True),
|
|
sa.Column('uid', sa.String(length=50), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('users', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_users_email'), ['email'], unique=True)
|
|
batch_op.create_index(batch_op.f('ix_users_role'), ['role'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_users_status'), ['status'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_users_username'), ['username'], unique=True)
|
|
|
|
op.create_table('reports',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('reporter_id', sa.Integer(), nullable=False),
|
|
sa.Column('reported_pt_site', sa.String(length=100), nullable=False),
|
|
sa.Column('reported_uid', sa.String(length=50), nullable=True),
|
|
sa.Column('reported_email', sa.String(length=120), nullable=False),
|
|
sa.Column('reason_category', sa.String(length=50), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=False),
|
|
sa.Column('status', sa.String(length=20), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(['reporter_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('reports', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_reports_created_at'), ['created_at'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_reports_reported_email'), ['reported_email'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_reports_status'), ['status'], unique=False)
|
|
|
|
op.create_table('blacklist',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('username', sa.String(length=64), nullable=True),
|
|
sa.Column('email', sa.String(length=120), nullable=True),
|
|
sa.Column('normalized_email', sa.String(length=120), nullable=True),
|
|
sa.Column('pt_site', sa.String(length=100), nullable=True),
|
|
sa.Column('uid', sa.String(length=50), nullable=True),
|
|
sa.Column('report_id', sa.Integer(), nullable=True),
|
|
sa.Column('status', sa.String(length=20), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(['report_id'], ['reports.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('report_id')
|
|
)
|
|
with op.batch_alter_table('blacklist', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_blacklist_created_at'), ['created_at'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_blacklist_email'), ['email'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_blacklist_normalized_email'), ['normalized_email'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_blacklist_pt_site'), ['pt_site'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_blacklist_status'), ['status'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_blacklist_username'), ['username'], unique=False)
|
|
|
|
op.create_table('comments',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('body', sa.Text(), nullable=True),
|
|
sa.Column('timestamp', sa.DateTime(), nullable=True),
|
|
sa.Column('author_id', sa.Integer(), nullable=True),
|
|
sa.Column('report_id', sa.Integer(), nullable=True),
|
|
sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
|
|
sa.ForeignKeyConstraint(['report_id'], ['reports.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('comments', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_comments_timestamp'), ['timestamp'], unique=False)
|
|
|
|
op.create_table('evidences',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('report_id', sa.Integer(), nullable=False),
|
|
sa.Column('file_url', sa.String(length=512), nullable=False),
|
|
sa.Column('file_type', sa.String(length=20), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(['report_id'], ['reports.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_table('appeals',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('reason', sa.Text(), nullable=False),
|
|
sa.Column('status', sa.String(length=64), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
|
sa.Column('appealer_id', sa.Integer(), nullable=True),
|
|
sa.Column('blacklist_entry_id', sa.Integer(), nullable=True),
|
|
sa.ForeignKeyConstraint(['appealer_id'], ['users.id'], ),
|
|
sa.ForeignKeyConstraint(['blacklist_entry_id'], ['blacklist.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('appeals', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_appeals_created_at'), ['created_at'], unique=False)
|
|
|
|
op.create_table('appeal_messages',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('body', sa.Text(), nullable=False),
|
|
sa.Column('timestamp', sa.DateTime(), nullable=True),
|
|
sa.Column('author_id', sa.Integer(), nullable=True),
|
|
sa.Column('appeal_id', sa.Integer(), nullable=True),
|
|
sa.ForeignKeyConstraint(['appeal_id'], ['appeals.id'], ),
|
|
sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('appeal_messages', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_appeal_messages_timestamp'), ['timestamp'], unique=False)
|
|
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
with op.batch_alter_table('appeal_messages', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_appeal_messages_timestamp'))
|
|
|
|
op.drop_table('appeal_messages')
|
|
with op.batch_alter_table('appeals', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_appeals_created_at'))
|
|
|
|
op.drop_table('appeals')
|
|
op.drop_table('evidences')
|
|
with op.batch_alter_table('comments', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_comments_timestamp'))
|
|
|
|
op.drop_table('comments')
|
|
with op.batch_alter_table('blacklist', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_blacklist_username'))
|
|
batch_op.drop_index(batch_op.f('ix_blacklist_status'))
|
|
batch_op.drop_index(batch_op.f('ix_blacklist_pt_site'))
|
|
batch_op.drop_index(batch_op.f('ix_blacklist_normalized_email'))
|
|
batch_op.drop_index(batch_op.f('ix_blacklist_email'))
|
|
batch_op.drop_index(batch_op.f('ix_blacklist_created_at'))
|
|
|
|
op.drop_table('blacklist')
|
|
with op.batch_alter_table('reports', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_reports_status'))
|
|
batch_op.drop_index(batch_op.f('ix_reports_reported_email'))
|
|
batch_op.drop_index(batch_op.f('ix_reports_created_at'))
|
|
|
|
op.drop_table('reports')
|
|
with op.batch_alter_table('users', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_users_username'))
|
|
batch_op.drop_index(batch_op.f('ix_users_status'))
|
|
batch_op.drop_index(batch_op.f('ix_users_role'))
|
|
batch_op.drop_index(batch_op.f('ix_users_email'))
|
|
|
|
op.drop_table('users')
|
|
# ### end Alembic commands ###
|