"""add profile resolver fields to config profiles and mounts Revision ID: 0014_add_profile_resolver_fields Revises: 0013_add_config_profiles Create Date: 2026-05-24 14:00:00.000000 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision: str = "0014_add_profile_resolver_fields" down_revision: Union[str, None] = "0013_add_config_profiles" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # Add fields to config_profiles op.add_column( "config_profiles", sa.Column("project_id", postgresql.UUID(as_uuid=True), nullable=True), ) op.add_column( "config_profiles", sa.Column("tool_type_id", postgresql.UUID(as_uuid=True), nullable=True), ) op.add_column( "config_profiles", sa.Column("environment_variables", sa.JSON(), nullable=True), ) op.add_column( "config_profiles", sa.Column("start_command", sa.Text(), nullable=True), ) op.add_column( "config_profiles", sa.Column("working_directory", sa.Text(), nullable=True), ) op.add_column( "config_profiles", sa.Column("port", sa.Integer(), nullable=True), ) op.add_column( "config_profiles", sa.Column("is_default", sa.Boolean(), nullable=False, server_default="false"), ) # Add foreign keys for project and tool_type op.create_foreign_key( "fk_config_profiles_project", "config_profiles", "projects", ["project_id"], ["id"], ondelete="CASCADE", ) op.create_foreign_key( "fk_config_profiles_tool_type", "config_profiles", "tool_types", ["tool_type_id"], ["id"], ondelete="CASCADE", ) # Create indices op.create_index("idx_config_profiles_project", "config_profiles", ["project_id"]) op.create_index("idx_config_profiles_tool_type", "config_profiles", ["tool_type_id"]) # Alter config_mounts: rename mount_path to target_path, add mode, change content to files JSON op.alter_column("config_mounts", "mount_path", new_column_name="target_path") op.add_column( "config_mounts", sa.Column("mode", sa.String(length=10), nullable=False, server_default="rw"), ) op.add_column( "config_mounts", sa.Column("files", sa.JSON(), nullable=True), ) # Drop the source_profile foreign key if it exists op.drop_constraint( "config_mounts_source_profile_id_fkey", "config_mounts", type_="foreignkey", ) op.drop_column("config_mounts", "content") op.drop_column("config_mounts", "source_profile_id") def downgrade() -> None: # Restore config_mounts op.add_column( "config_mounts", sa.Column("source_profile_id", postgresql.UUID(as_uuid=True), nullable=True), ) op.add_column( "config_mounts", sa.Column("content", sa.Text(), nullable=True), ) op.drop_column("config_mounts", "files") op.drop_column("config_mounts", "mode") op.alter_column("config_mounts", "target_path", new_column_name="mount_path") # Restore config_profiles op.drop_index("idx_config_profiles_tool_type", table_name="config_profiles") op.drop_index("idx_config_profiles_project", table_name="config_profiles") op.drop_constraint("fk_config_profiles_tool_type", "config_profiles", type_="foreignkey") op.drop_constraint("fk_config_profiles_project", "config_profiles", type_="foreignkey") op.drop_column("config_profiles", "is_default") op.drop_column("config_profiles", "port") op.drop_column("config_profiles", "working_directory") op.drop_column("config_profiles", "start_command") op.drop_column("config_profiles", "environment_variables") op.drop_column("config_profiles", "tool_type_id") op.drop_column("config_profiles", "project_id")