2aec488226
Detect 302→303 within 1–10s, Problem with 30s dedup, rdg_flap flag. Agent command poll API, admin qwinsta/logoff from Overview. Migration 016.
47 lines
2.1 KiB
Python
47 lines
2.1 KiB
Python
"""Revision ID: 016
|
|
Revises: 015
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
revision: str = "016"
|
|
down_revision: Union[str, None] = "015"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"agent_commands",
|
|
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column("command_uuid", sa.String(length=36), nullable=False),
|
|
sa.Column("host_id", sa.Integer(), nullable=False),
|
|
sa.Column("event_id", sa.Integer(), nullable=True),
|
|
sa.Column("command_type", sa.String(length=32), nullable=False),
|
|
sa.Column("params", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
|
|
sa.Column("status", sa.String(length=16), nullable=False, server_default="pending"),
|
|
sa.Column("result_stdout", sa.Text(), nullable=True),
|
|
sa.Column("result_stderr", sa.Text(), nullable=True),
|
|
sa.Column("requested_by", sa.String(length=128), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
|
|
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(["event_id"], ["events.id"], ondelete="SET NULL"),
|
|
sa.ForeignKeyConstraint(["host_id"], ["hosts.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("command_uuid"),
|
|
)
|
|
op.create_index("ix_agent_commands_command_uuid", "agent_commands", ["command_uuid"])
|
|
op.create_index("ix_agent_commands_host_id", "agent_commands", ["host_id"])
|
|
op.create_index("ix_agent_commands_status", "agent_commands", ["status"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_agent_commands_status", table_name="agent_commands")
|
|
op.drop_index("ix_agent_commands_host_id", table_name="agent_commands")
|
|
op.drop_index("ix_agent_commands_command_uuid", table_name="agent_commands")
|
|
op.drop_table("agent_commands")
|