"""add_clone_mode_and_ssh_key_id

Revision ID: 2026_05_22_add_clone_mode
Revises: 0014_merge_heads
Create Date: 2026-05-22 20:30:00.000000
"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '2026_05_22_add_clone_mode'
down_revision = '0015_single_interface'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # Add ssh_key_id to git_repositories
    op.add_column('git_repositories', sa.Column('ssh_key_id', postgresql.UUID(), nullable=True))
    op.create_foreign_key('fk_git_repositories_ssh_key', 'git_repositories', 'ssh_keys', ['ssh_key_id'], ['id'])
    
    # Add clone_mode and branch to tool_instances
    op.add_column('tool_instances', sa.Column('clone_mode', sa.String(20), nullable=False, server_default='mount'))
    op.add_column('tool_instances', sa.Column('branch', sa.String(255), nullable=True, server_default='main'))


def downgrade() -> None:
    # Drop columns from tool_instances
    op.drop_column('tool_instances', 'branch')
    op.drop_column('tool_instances', 'clone_mode')
    
    # Drop ssh_key_id from git_repositories
    op.drop_constraint('fk_git_repositories_ssh_key', 'git_repositories', type_='foreignkey')
    op.drop_column('git_repositories', 'ssh_key_id')
