bifroest/app/migrations/versions/0003_tools.py
2026-10-27 08:34:17 +01:00

70 lines
3.3 KiB
Python

"""Tools
Revision ID: 0003
Revises: 0002
Erstellt: 2026-10-21 22:52:32.834522
"""
from alembic import op
import sqlalchemy as sa
revision = '0003'
down_revision = '0002'
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table('tool_definitions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('kind', sa.String(length=20), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('schema', sa.JSON(), nullable=False),
sa.Column('hash', sa.String(length=64), nullable=False),
sa.Column('suggested_risk', sa.String(length=20), nullable=False),
sa.Column('risk_class', sa.String(length=20), nullable=True),
sa.Column('decision', sa.String(length=20), nullable=True),
sa.Column('classified_hash', sa.String(length=64), nullable=True),
sa.Column('classified_by', sa.Integer(), nullable=True),
sa.Column('classified_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('updated', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['classified_by'], ['users.id'], name=op.f('fk_tool_definitions_classified_by_users')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_tool_definitions')),
sa.UniqueConstraint('name', name=op.f('uq_tool_definitions_name'))
)
op.create_table('workspace_tool_policies',
sa.Column('workspace_id', sa.Integer(), nullable=False),
sa.Column('tool_name', sa.String(length=100), nullable=False),
sa.Column('decision', sa.String(length=20), nullable=False),
sa.Column('updated_by', sa.Integer(), nullable=False),
sa.Column('updated', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['updated_by'], ['users.id'], name=op.f('fk_workspace_tool_policies_updated_by_users')),
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], name=op.f('fk_workspace_tool_policies_workspace_id_workspaces'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('workspace_id', 'tool_name', name=op.f('pk_workspace_tool_policies'))
)
op.create_table('tool_calls',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('run_id', sa.Uuid(), nullable=False),
sa.Column('workspace_id', sa.Integer(), nullable=False),
sa.Column('call_id', sa.String(length=200), nullable=False),
sa.Column('tool', sa.String(length=200), nullable=False),
sa.Column('arguments', sa.JSON(), nullable=False),
sa.Column('decision', sa.String(length=20), nullable=False),
sa.Column('status', sa.String(length=20), nullable=False),
sa.Column('output', sa.Text(), nullable=False),
sa.Column('duration_ms', sa.Integer(), nullable=False),
sa.Column('created', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['run_id'], ['task_runs.id'], name=op.f('fk_tool_calls_run_id_task_runs'), ondelete='CASCADE'),
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], name=op.f('fk_tool_calls_workspace_id_workspaces'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id', name=op.f('pk_tool_calls'))
)
op.create_index('ix_tool_calls_run_id', 'tool_calls', ['run_id'], unique=False)
def downgrade() -> None:
op.drop_index('ix_tool_calls_run_id', table_name='tool_calls')
op.drop_table('tool_calls')
op.drop_table('workspace_tool_policies')
op.drop_table('tool_definitions')