Files
headquarter/apps/api/alembic/versions/6cfa61694d0a_initial_schema.py
T
2026-05-14 06:47:30 +02:00

173 lines
9.0 KiB
Python

"""initial schema
Revision ID: 6cfa61694d0a
Revises:
Create Date: 2026-05-14 06:16:27.700389
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '6cfa61694d0a'
down_revision: Union[str, Sequence[str], None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('secret',
sa.Column('scope_type', sa.String(length=50), nullable=False),
sa.Column('scope_id', sa.Uuid(), nullable=False),
sa.Column('key', sa.String(length=255), nullable=False),
sa.Column('encrypted_value', sa.Text(), nullable=False),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('scope_type', 'scope_id', 'key')
)
op.create_index(op.f('ix_secret_scope_id'), 'secret', ['scope_id'], unique=False)
op.create_table('tool_definition',
sa.Column('key', sa.String(length=100), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('version', sa.String(length=50), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('image', sa.Text(), nullable=False),
sa.Column('manifest_data', sa.JSON(), nullable=True),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_tool_definition_key'), 'tool_definition', ['key'], unique=True)
op.create_table('user',
sa.Column('authentik_sub', sa.String(length=255), nullable=False),
sa.Column('email', sa.String(length=255), nullable=False),
sa.Column('display_name', sa.String(length=255), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_user_authentik_sub'), 'user', ['authentik_sub'], unique=True)
op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
op.create_table('config',
sa.Column('scope_type', sa.String(length=50), nullable=False),
sa.Column('scope_id', sa.Uuid(), nullable=False),
sa.Column('tool_definition_id', sa.Uuid(), nullable=True),
sa.Column('key', sa.String(length=255), nullable=False),
sa.Column('value', sa.JSON(), nullable=False),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['tool_definition_id'], ['tool_definition.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('scope_type', 'scope_id', 'tool_definition_id', 'key')
)
op.create_index(op.f('ix_config_scope_id'), 'config', ['scope_id'], unique=False)
op.create_index(op.f('ix_config_tool_definition_id'), 'config', ['tool_definition_id'], unique=False)
op.create_table('project',
sa.Column('owner_id', sa.Uuid(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('slug', sa.String(length=255), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('owner_id', 'slug')
)
op.create_index(op.f('ix_project_owner_id'), 'project', ['owner_id'], unique=False)
op.create_table('repository',
sa.Column('project_id', sa.Uuid(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('git_url', sa.Text(), nullable=False),
sa.Column('provider_type', sa.String(length=50), nullable=False),
sa.Column('default_branch', sa.String(length=100), nullable=False),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['project_id'], ['project.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_repository_project_id'), 'repository', ['project_id'], unique=False)
op.create_table('tool_instance',
sa.Column('project_id', sa.Uuid(), nullable=False),
sa.Column('tool_definition_id', sa.Uuid(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('status', sa.String(length=50), nullable=False),
sa.Column('container_id', sa.String(length=255), nullable=True),
sa.Column('subdomain', sa.String(length=255), nullable=True),
sa.Column('config_override', sa.JSON(), nullable=True),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['project_id'], ['project.id'], ),
sa.ForeignKeyConstraint(['tool_definition_id'], ['tool_definition.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('subdomain')
)
op.create_index(op.f('ix_tool_instance_project_id'), 'tool_instance', ['project_id'], unique=False)
op.create_index(op.f('ix_tool_instance_tool_definition_id'), 'tool_instance', ['tool_definition_id'], unique=False)
op.create_table('workspace',
sa.Column('project_id', sa.Uuid(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('mount_path', sa.Text(), nullable=True),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['project_id'], ['project.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_workspace_project_id'), 'workspace', ['project_id'], unique=False)
op.create_table('access_route',
sa.Column('tool_instance_id', sa.Uuid(), nullable=False),
sa.Column('domain', sa.Text(), nullable=False),
sa.Column('path_prefix', sa.String(length=255), nullable=False),
sa.Column('provider_type', sa.String(length=50), nullable=False),
sa.Column('provider_config', sa.JSON(), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['tool_instance_id'], ['tool_instance.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_access_route_tool_instance_id'), 'access_route', ['tool_instance_id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_access_route_tool_instance_id'), table_name='access_route')
op.drop_table('access_route')
op.drop_index(op.f('ix_workspace_project_id'), table_name='workspace')
op.drop_table('workspace')
op.drop_index(op.f('ix_tool_instance_tool_definition_id'), table_name='tool_instance')
op.drop_index(op.f('ix_tool_instance_project_id'), table_name='tool_instance')
op.drop_table('tool_instance')
op.drop_index(op.f('ix_repository_project_id'), table_name='repository')
op.drop_table('repository')
op.drop_index(op.f('ix_project_owner_id'), table_name='project')
op.drop_table('project')
op.drop_index(op.f('ix_config_tool_definition_id'), table_name='config')
op.drop_index(op.f('ix_config_scope_id'), table_name='config')
op.drop_table('config')
op.drop_index(op.f('ix_user_email'), table_name='user')
op.drop_index(op.f('ix_user_authentik_sub'), table_name='user')
op.drop_table('user')
op.drop_index(op.f('ix_tool_definition_key'), table_name='tool_definition')
op.drop_table('tool_definition')
op.drop_index(op.f('ix_secret_scope_id'), table_name='secret')
op.drop_table('secret')
# ### end Alembic commands ###