- SimulationTemplate model + migration 0005 (CREATE TABLE + name index) - 5 CRUD endpoints under /api/templates (admin|redteam only, SOC 403) - POST /api/engagements/<eid>/simulations extended with optional template_id - serialize_template() reusing _enrich_techniques/_enrich_tactics helpers - IntegrityError → 409 for duplicate name on both POST and PATCH - 28 new tests (CRUD, RBAC, dedup, instantiation, migration round-trip) - 221 tests pass; ruff clean; mypy clean Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""create simulation_templates table
|
|
|
|
Revision ID: 0005
|
|
Revises: 0004
|
|
Create Date: 2026-05-28 00:00:00.000000
|
|
"""
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision = "0005"
|
|
down_revision = "0004"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"simulation_templates",
|
|
sa.Column("id", sa.Integer(), primary_key=True),
|
|
sa.Column("name", sa.String(length=255), nullable=False, unique=True),
|
|
sa.Column("description", sa.Text(), nullable=True),
|
|
sa.Column("commands", sa.Text(), nullable=True),
|
|
sa.Column("prerequisites", sa.Text(), nullable=True),
|
|
sa.Column("techniques", sa.JSON(), nullable=False, server_default=sa.text("'[]'")),
|
|
sa.Column("tactic_ids", sa.JSON(), nullable=False, server_default=sa.text("'[]'")),
|
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(), nullable=True),
|
|
sa.Column(
|
|
"created_by_id",
|
|
sa.Integer(),
|
|
sa.ForeignKey("users.id", ondelete="RESTRICT"),
|
|
nullable=False,
|
|
),
|
|
)
|
|
op.create_index("ix_simulation_templates_name", "simulation_templates", ["name"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_simulation_templates_name", "simulation_templates")
|
|
op.drop_table("simulation_templates")
|