- Environment model (prefix, name, description) with CRUD API - Ticket.human_id now computed from environment prefix (e.g. PROJ-001) - Migration 0002: environments table + backfill existing tickets to HOME env - Router: list/create/get/patch/delete environments; list_tickets + create_ticket accept environment_id - MCP: list_environments, create_environment tools; environment_id added to list_tickets + create_ticket - UI: env pill selector with dropdown, new-environment modal, filter tickets by env Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Add environments table and environment_id FK on tickets
|
|
|
|
Revision ID: 0002
|
|
Revises: 0001
|
|
Create Date: 2026-05-25
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "0002"
|
|
down_revision: Union[str, None] = "0001"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"environments",
|
|
sa.Column("id", sa.Integer(), primary_key=True),
|
|
sa.Column("prefix", sa.String(16), nullable=False, unique=True),
|
|
sa.Column("name", sa.String(64), nullable=False),
|
|
sa.Column("description", sa.Text(), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False,
|
|
server_default=sa.func.now()),
|
|
)
|
|
|
|
op.execute("INSERT INTO environments (prefix, name) VALUES ('HOME', 'Homelab')")
|
|
|
|
op.add_column("tickets",
|
|
sa.Column("environment_id", sa.Integer(),
|
|
sa.ForeignKey("environments.id", ondelete="SET NULL"), nullable=True))
|
|
|
|
op.execute(
|
|
"UPDATE tickets SET environment_id = (SELECT id FROM environments WHERE prefix = 'HOME')"
|
|
)
|
|
|
|
op.create_index("ix_tickets_environment_id", "tickets", ["environment_id"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_tickets_environment_id", table_name="tickets")
|
|
op.drop_column("tickets", "environment_id")
|
|
op.drop_table("environments")
|