feat(l4d2-web): add command_history table for RCON console transcript
A row per RCON command execution: (user, server, command, reply, is_error, created_at). Composite index on (user_id, server_id, id) supports the only query shape — "latest N for this user+server", id DESC. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9ef9ffdbde
commit
c4dffd471b
2 changed files with 71 additions and 0 deletions
48
l4d2web/alembic/versions/0012_command_history.py
Normal file
48
l4d2web/alembic/versions/0012_command_history.py
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
"""add command_history table
|
||||||
|
|
||||||
|
Revision ID: 0012_command_history
|
||||||
|
Revises: 0011_server_hostname
|
||||||
|
Create Date: 2026-05-14
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
|
||||||
|
revision: str = "0012_command_history"
|
||||||
|
down_revision: Union[str, Sequence[str], None] = "0011_server_hostname"
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
op.create_table(
|
||||||
|
"command_history",
|
||||||
|
sa.Column("id", sa.Integer(), primary_key=True),
|
||||||
|
sa.Column("user_id", sa.Integer(), sa.ForeignKey("users.id"), nullable=False),
|
||||||
|
sa.Column(
|
||||||
|
"server_id",
|
||||||
|
sa.Integer(),
|
||||||
|
sa.ForeignKey("servers.id", ondelete="CASCADE"),
|
||||||
|
nullable=False,
|
||||||
|
),
|
||||||
|
sa.Column("command", sa.Text(), nullable=False),
|
||||||
|
sa.Column("reply", sa.Text(), nullable=False, server_default=""),
|
||||||
|
sa.Column(
|
||||||
|
"is_error", sa.Boolean(), nullable=False, server_default=sa.text("0")
|
||||||
|
),
|
||||||
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
"ix_cmdhist_user_server_id",
|
||||||
|
"command_history",
|
||||||
|
["user_id", "server_id", "id"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
op.drop_index("ix_cmdhist_user_server_id", table_name="command_history")
|
||||||
|
op.drop_table("command_history")
|
||||||
|
|
@ -227,3 +227,26 @@ class SteamUserProfile(Base):
|
||||||
persona_name: Mapped[str] = mapped_column(String(64), nullable=False)
|
persona_name: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||||
avatar_url: Mapped[str] = mapped_column(Text, nullable=False)
|
avatar_url: Mapped[str] = mapped_column(Text, nullable=False)
|
||||||
fetched_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
fetched_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandHistory(Base):
|
||||||
|
__tablename__ = "command_history"
|
||||||
|
__table_args__ = (
|
||||||
|
Index("ix_cmdhist_user_server_id", "user_id", "server_id", "id"),
|
||||||
|
)
|
||||||
|
|
||||||
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||||
|
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
|
||||||
|
server_id: Mapped[int] = mapped_column(
|
||||||
|
ForeignKey("servers.id", ondelete="CASCADE"), nullable=False
|
||||||
|
)
|
||||||
|
command: Mapped[str] = mapped_column(Text, nullable=False)
|
||||||
|
reply: Mapped[str] = mapped_column(
|
||||||
|
Text, nullable=False, default="", server_default=""
|
||||||
|
)
|
||||||
|
is_error: Mapped[bool] = mapped_column(
|
||||||
|
Boolean, nullable=False, default=False, server_default=text("0")
|
||||||
|
)
|
||||||
|
created_at: Mapped[datetime] = mapped_column(
|
||||||
|
DateTime, default=now_utc, nullable=False
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue