"""add_tool_type_fields

Revision ID: af8512103d67
Revises: 0012_default_port_req
Create Date: 2026-05-22 18:37:56.607240
"""

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

# revision identifiers, used by Alembic.
revision = 'af8512103d67'
down_revision = '0012_default_port_req'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # Add new columns to tool_types
    op.add_column('tool_types', sa.Column('definition_type', sa.String(20), nullable=False, server_default='compose'))
    op.add_column('tool_types', sa.Column('dockerfile_template', sa.Text(), nullable=True))
    op.add_column('tool_types', sa.Column('build_context', postgresql.JSONB(astext_type=sa.Text()), nullable=True, server_default='{}'))
    op.add_column('tool_types', sa.Column('readiness_probe', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
    
    # Add CHECK constraint for definition_type
    op.create_check_constraint('chk_definition_type', 'tool_types', sa.text("definition_type IN ('compose', 'dockerfile')"))


def downgrade() -> None:
    # Drop CHECK constraint
    op.drop_constraint('chk_definition_type', 'tool_types', type_='check')
    
    # Drop columns
    op.drop_column('tool_types', 'definition_type')
    op.drop_column('tool_types', 'dockerfile_template')
    op.drop_column('tool_types', 'build_context')
    op.drop_column('tool_types', 'readiness_probe')
