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

92 lines
4.8 KiB
Python

"""Hugin-Anbindung: Host der Plattform, Zugang je Workspace, gewählte und festgeschriebene Pakete je Workspace
Revision ID: 0024
Revises: 0023
Erstellt: 2026-10-25 16:27:30.682634
"""
import sqlalchemy as sa
from alembic import op
revision = '0024'
down_revision = '0023'
branch_labels = None
depends_on = None
# Namen der Fremdschlüssel aus 0022 an die Namenskonvention angleichen (in neuen Datenbanken schon richtig)
RENAMES = [("mcp_servers_workspace_id_fkey", "fk_mcp_servers_workspace_id_workspaces"),
("mcp_servers_template_id_fkey", "fk_mcp_servers_template_id_mcp_servers"),
("mcp_servers_exposure_confirmed_by_fkey", "fk_mcp_servers_exposure_confirmed_by_users")]
def upgrade() -> None:
for old, new in RENAMES:
op.execute(f"""DO $$ BEGIN
IF EXISTS (SELECT 1 FROM pg_constraint WHERE conname = '{old}') THEN
ALTER TABLE mcp_servers RENAME CONSTRAINT {old} TO {new};
END IF; END $$""")
op.create_table('hugin_host',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('url', sa.String(length=500), nullable=False),
sa.Column('status', sa.String(length=16), nullable=False),
sa.Column('status_message', sa.Text(), nullable=False),
sa.Column('checked', sa.DateTime(timezone=True), nullable=True),
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_hugin_host_updated_by_users')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_hugin_host'))
)
op.create_table('workspace_hugin',
sa.Column('workspace_id', sa.Integer(), nullable=False),
sa.Column('secret', sa.Text(), nullable=False),
sa.Column('hint', sa.String(length=8), nullable=False),
sa.Column('status', sa.String(length=16), nullable=False),
sa.Column('status_message', sa.Text(), nullable=False),
sa.Column('tenant', sa.String(length=64), nullable=False),
sa.Column('key_name', sa.String(length=200), nullable=False),
sa.Column('checked', sa.DateTime(timezone=True), nullable=True),
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_hugin_updated_by_users')),
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], name=op.f('fk_workspace_hugin_workspace_id_workspaces'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('workspace_id', name=op.f('pk_workspace_hugin'))
)
op.create_table('workspace_hugin_locks',
sa.Column('workspace_id', sa.Integer(), nullable=False),
sa.Column('package_id', sa.String(length=64), nullable=False),
sa.Column('kind', sa.String(length=16), nullable=False),
sa.Column('version', sa.String(length=32), nullable=False),
sa.Column('checksum', sa.String(length=80), nullable=False),
sa.Column('risk', sa.String(length=16), nullable=False),
sa.Column('mandatory', sa.Boolean(), nullable=False),
sa.Column('deprecated', sa.Boolean(), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('arguments', sa.JSON(), nullable=False),
sa.Column('archive', sa.LargeBinary(), nullable=False),
sa.Column('archive_sha256', sa.String(length=64), nullable=False),
sa.Column('unsupported', sa.Text(), nullable=False),
sa.Column('locked_by', sa.Integer(), nullable=False),
sa.Column('locked', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['locked_by'], ['users.id'], name=op.f('fk_workspace_hugin_locks_locked_by_users')),
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], name=op.f('fk_workspace_hugin_locks_workspace_id_workspaces'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('workspace_id', 'package_id', name=op.f('pk_workspace_hugin_locks'))
)
op.create_table('workspace_hugin_packages',
sa.Column('workspace_id', sa.Integer(), nullable=False),
sa.Column('package_id', sa.String(length=64), nullable=False),
sa.Column('spec', sa.String(length=32), nullable=False),
sa.Column('added_by', sa.Integer(), nullable=False),
sa.Column('added', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['added_by'], ['users.id'], name=op.f('fk_workspace_hugin_packages_added_by_users')),
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], name=op.f('fk_workspace_hugin_packages_workspace_id_workspaces'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('workspace_id', 'package_id', name=op.f('pk_workspace_hugin_packages'))
)
def downgrade() -> None:
op.drop_table('workspace_hugin_packages')
op.drop_table('workspace_hugin_locks')
op.drop_table('workspace_hugin')
op.drop_table('hugin_host')