Files
DocsGPT/application/alembic/versions/0019_agent_slug.py
T
Alex 3e968be6cc Merge origin/main into agent-exports; renumber agent-slug migration to 0019
main added migration 0018_tool_attempts_attribution (revises 0017_oidc_scim), which collided with the feature's 0018_agent_slug. Renumbered the agent-slug migration to 0019 (revises 0018_tool_attempts_attribution) so the Alembic chain stays linear (single head). Auto-merge was conflict-free — models.py, the frontend API layer, and all 7 locale files merged additively.
2026-06-13 14:42:50 +01:00

37 lines
1.1 KiB
Python

"""0019 agent slug — stable per-user identifier for YAML export/import.
Adds ``agents.slug`` (CITEXT) plus a partial unique index on
``(user_id, slug)`` where slug is not null, so an exported agent can be
re-imported idempotently (and mapped from a repo file for GitOps) while
still allowing multiple agents to carry NULL. Idempotent both ways.
Revision ID: 0019_agent_slug
Revises: 0018_tool_attempts_attribution
"""
from typing import Sequence, Union
from alembic import op
revision: str = "0019_agent_slug"
down_revision: Union[str, None] = "0018_tool_attempts_attribution"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.execute("ALTER TABLE agents ADD COLUMN IF NOT EXISTS slug CITEXT;")
op.execute(
"""
CREATE UNIQUE INDEX IF NOT EXISTS ix_agents_user_slug
ON agents (user_id, slug)
WHERE slug IS NOT NULL;
"""
)
def downgrade() -> None:
op.execute("DROP INDEX IF EXISTS ix_agents_user_slug;")
op.execute("ALTER TABLE agents DROP COLUMN IF EXISTS slug;")