feat(docker): schema for lifecycle events + swarm topology
Adds the milestone-77 storage that doesn't fit on the per-container row:
* docker_events — lifecycle (start/stop/die/oom/health_change), to be
derived by diffing consecutive host snapshots; host-scoped, indexed for
timeline lookups (host_id, container_name, at) and retention pruning (at).
* docker_swarm_services / docker_swarm_nodes — manager-reported Swarm
topology (desired-vs-running replicas, node role/availability/status).
Migration docker_004 extends the docker branch (down_revision docker_003);
purely additive, no DROP+recreate. event/mode/role are plain strings (no
CHECK whitelist), matching how docker_containers models status. Integration
guard asserts the three new host-scoped tables exist.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Jg27rgypiW2efULXJDtMC
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
"""Docker lifecycle events + swarm topology tables
|
||||
|
||||
Adds the storage for milestone-77 monitoring depth that doesn't fit on the
|
||||
per-container row:
|
||||
|
||||
* docker_events — lifecycle (start/stop/die/oom/health_change) derived by
|
||||
diffing consecutive host snapshots; host-scoped, indexed for both timeline
|
||||
lookups (host_id, container_name, at) and retention pruning (at).
|
||||
* docker_swarm_services / docker_swarm_nodes — manager-reported Swarm
|
||||
topology (desired-vs-running replicas, node role/availability/status).
|
||||
|
||||
All new tables — purely additive, so no DROP+recreate. `event`/`mode`/`role`
|
||||
etc. are plain strings (no CHECK whitelist), matching how docker_containers
|
||||
models `status`; keeps the value sets open without a migration per addition
|
||||
(so rule 36 doesn't apply here).
|
||||
|
||||
Revision ID: docker_004_events_swarm
|
||||
Revises: docker_003_container_enrichment
|
||||
Create Date: 2026-06-19
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision: str = "docker_004_events_swarm"
|
||||
down_revision: Union[str, None] = "docker_003_container_enrichment"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"docker_events",
|
||||
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("container_name", sa.String(255), nullable=False),
|
||||
sa.Column("event", sa.String(16), nullable=False),
|
||||
sa.Column("detail", sa.String(255), nullable=True),
|
||||
sa.Column("at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_index("ix_docker_events_host_container_time", "docker_events",
|
||||
["host_id", "container_name", "at"])
|
||||
op.create_index("ix_docker_events_at", "docker_events", ["at"])
|
||||
|
||||
op.create_table(
|
||||
"docker_swarm_services",
|
||||
sa.Column("host_id", sa.String(36),
|
||||
sa.ForeignKey("hosts.id", ondelete="CASCADE"), primary_key=True),
|
||||
sa.Column("service_name", sa.String(255), primary_key=True),
|
||||
sa.Column("mode", sa.String(16), nullable=False, server_default="replicated"),
|
||||
sa.Column("desired", sa.Integer, nullable=False, server_default="0"),
|
||||
sa.Column("running", sa.Integer, nullable=False, server_default="0"),
|
||||
sa.Column("image", sa.String(512), nullable=True),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"docker_swarm_nodes",
|
||||
sa.Column("host_id", sa.String(36),
|
||||
sa.ForeignKey("hosts.id", ondelete="CASCADE"), primary_key=True),
|
||||
sa.Column("node_id", sa.String(64), primary_key=True),
|
||||
sa.Column("hostname", sa.String(255), nullable=False, server_default=""),
|
||||
sa.Column("role", sa.String(16), nullable=False, server_default="worker"),
|
||||
sa.Column("availability", sa.String(16), nullable=False, server_default="active"),
|
||||
sa.Column("status", sa.String(16), nullable=False, server_default="unknown"),
|
||||
sa.Column("leader", sa.Boolean, nullable=False, server_default=sa.false()),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("docker_swarm_nodes")
|
||||
op.drop_table("docker_swarm_services")
|
||||
op.drop_index("ix_docker_events_at", table_name="docker_events")
|
||||
op.drop_index("ix_docker_events_host_container_time", table_name="docker_events")
|
||||
op.drop_table("docker_events")
|
||||
Reference in New Issue
Block a user