39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""create exceptions table
|
|
|
|
Revision ID: a2b3c4d5e6f7
|
|
Revises: 0001
|
|
Create Date: 2024-03-26 12:00:00.000000
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.sql import func
|
|
|
|
# revision identifiers
|
|
revision = 'a2b3c4d5e6f7'
|
|
down_revision = '0001'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
def upgrade():
|
|
op.create_table(
|
|
'exceptions',
|
|
sa.Column('id', UUID(as_uuid=True), primary_key=True, default=sa.text('gen_random_uuid()')),
|
|
sa.Column('endpoint', sa.String(), nullable=False),
|
|
sa.Column('method', sa.String(), nullable=False),
|
|
sa.Column('status_code', sa.String(), nullable=False),
|
|
sa.Column('error_message', sa.Text(), nullable=True),
|
|
sa.Column('stack_trace', sa.Text(), nullable=True),
|
|
sa.Column('request_data', sa.Text(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
|
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now())
|
|
)
|
|
|
|
# Create index on frequently queried columns
|
|
op.create_index('idx_exceptions_endpoint', 'exceptions', ['endpoint'])
|
|
op.create_index('idx_exceptions_created_at', 'exceptions', ['created_at'])
|
|
|
|
def downgrade():
|
|
op.drop_index('idx_exceptions_created_at')
|
|
op.drop_index('idx_exceptions_endpoint')
|
|
op.drop_table('exceptions') |