54 lines
2.4 KiB
Python
54 lines
2.4 KiB
Python
"""Initial schema for alert processor
|
|
|
|
Revision ID: 00000001
|
|
Revises:
|
|
Create Date: 2025-09-30 18:00:00.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '000001'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Create alerts table (ENUMs will be created automatically)
|
|
op.create_table('alerts',
|
|
sa.Column('id', sa.UUID(), nullable=False),
|
|
sa.Column('tenant_id', sa.UUID(), nullable=False),
|
|
sa.Column('item_type', sa.String(length=50), nullable=False),
|
|
sa.Column('alert_type', sa.String(length=100), nullable=False),
|
|
sa.Column('severity', sa.Enum('LOW', 'MEDIUM', 'HIGH', 'URGENT', name='alertseverity'), nullable=False),
|
|
sa.Column('status', sa.Enum('ACTIVE', 'RESOLVED', 'ACKNOWLEDGED', 'IGNORED', name='alertstatus'), nullable=False),
|
|
sa.Column('service', sa.String(length=100), nullable=False),
|
|
sa.Column('title', sa.String(length=255), nullable=False),
|
|
sa.Column('message', sa.Text(), nullable=False),
|
|
sa.Column('actions', postgresql.JSON(astext_type=sa.Text()), nullable=True),
|
|
sa.Column('alert_metadata', postgresql.JSON(astext_type=sa.Text()), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
|
sa.Column('resolved_at', sa.DateTime(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_alerts_tenant_id'), 'alerts', ['tenant_id'], unique=False)
|
|
op.create_index(op.f('ix_alerts_severity'), 'alerts', ['severity'], unique=False)
|
|
op.create_index(op.f('ix_alerts_status'), 'alerts', ['status'], unique=False)
|
|
op.create_index(op.f('ix_alerts_created_at'), 'alerts', ['created_at'], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f('ix_alerts_created_at'), table_name='alerts')
|
|
op.drop_index(op.f('ix_alerts_status'), table_name='alerts')
|
|
op.drop_index(op.f('ix_alerts_severity'), table_name='alerts')
|
|
op.drop_index(op.f('ix_alerts_tenant_id'), table_name='alerts')
|
|
op.drop_table('alerts')
|
|
|
|
# Drop enums (will be dropped automatically with table, but explicit for clarity)
|
|
sa.Enum(name='alertseverity').drop(op.get_bind(), checkfirst=True)
|
|
sa.Enum(name='alertstatus').drop(op.get_bind(), checkfirst=True)
|