# plugins/host_agent/migrations/versions/host_agent_004_downtime.py """host_agent: each host's downtime and what it was (#5756) Revision ID: host_agent_004_downtime """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa revision: str = "host_agent_004_downtime" down_revision: Union[str, None] = "host_agent_003_clock_offset" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: op.create_table( "host_downtime", sa.Column("id", sa.String(36), primary_key=True), sa.Column("host_id", sa.String(36), sa.ForeignKey("hosts.id", ondelete="CASCADE"), nullable=False), sa.Column("kind", sa.String(16), nullable=False), sa.Column("started_at", sa.DateTime(timezone=True), nullable=False), sa.Column("ended_at", sa.DateTime(timezone=True), nullable=True), sa.Column("created_at", sa.DateTime(timezone=True), nullable=False), ) op.create_index("ix_host_downtime_host_id", "host_downtime", ["host_id"]) def downgrade() -> None: op.drop_index("ix_host_downtime_host_id", table_name="host_downtime") op.drop_table("host_downtime")