Refactor services alembic
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""Initial alert-processor service tables
|
||||
|
||||
Revision ID: 001_initial_alert_processor
|
||||
Revises:
|
||||
Create Date: 2024-01-01 12:00:00.000000
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '001_initial_alert_processor'
|
||||
down_revision: Union[str, None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# TODO: Add table creation statements for alert_processor service
|
||||
# This is a placeholder migration - replace with actual table definitions
|
||||
pass
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# TODO: Add table drop statements for alert_processor service
|
||||
pass
|
||||
@@ -1,64 +0,0 @@
|
||||
"""Initial alerts table
|
||||
|
||||
Revision ID: 001
|
||||
Revises:
|
||||
Create Date: 2025-09-18 23:17:00
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '001'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Create enum types
|
||||
alert_status_enum = postgresql.ENUM('active', 'resolved', 'acknowledged', 'ignored', name='alertstatus')
|
||||
alert_severity_enum = postgresql.ENUM('low', 'medium', 'high', 'urgent', name='alertseverity')
|
||||
|
||||
alert_status_enum.create(op.get_bind())
|
||||
alert_severity_enum.create(op.get_bind())
|
||||
|
||||
# Create alerts table
|
||||
op.create_table('alerts',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column('tenant_id', postgresql.UUID(as_uuid=True), 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', alert_severity_enum, nullable=False),
|
||||
sa.Column('status', alert_status_enum, 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', sa.JSON(), nullable=True),
|
||||
sa.Column('metadata', sa.JSON(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('resolved_at', sa.DateTime(), nullable=True),
|
||||
)
|
||||
|
||||
# Create indexes
|
||||
op.create_index('ix_alerts_tenant_id', 'alerts', ['tenant_id'])
|
||||
op.create_index('ix_alerts_severity', 'alerts', ['severity'])
|
||||
op.create_index('ix_alerts_status', 'alerts', ['status'])
|
||||
op.create_index('ix_alerts_created_at', 'alerts', ['created_at'])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Drop indexes
|
||||
op.drop_index('ix_alerts_created_at', 'alerts')
|
||||
op.drop_index('ix_alerts_status', 'alerts')
|
||||
op.drop_index('ix_alerts_severity', 'alerts')
|
||||
op.drop_index('ix_alerts_tenant_id', 'alerts')
|
||||
|
||||
# Drop table
|
||||
op.drop_table('alerts')
|
||||
|
||||
# Drop enum types
|
||||
op.execute('DROP TYPE alertseverity')
|
||||
op.execute('DROP TYPE alertstatus')
|
||||
Reference in New Issue
Block a user