"""Initial migration

Revision ID: initial
Revises: 
Create Date: 2025-11-06 00:00:00.000000

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'initial'
down_revision = None
branch_labels = None
depends_on = None

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tasks',
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('project_id', sa.String(length=36), nullable=False),
        sa.Column('project_name', sa.String(length=255), nullable=False),
        sa.Column('compute_hostname', sa.String(length=255), nullable=False),
        sa.Column('scheduled_time', sa.DateTime(), nullable=True),
        sa.Column('state', sa.Enum('SCHEDULED', 'ERROR', 'RUNNING', 'DONE', name='taskstate'), nullable=False),
        sa.Column('task_type', sa.Enum('EVACUATE', 'PROJECT_PURGE', 'VALIDATE_COMPUTE', name='tasktype'), nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint('id')
    )

    op.create_table('services',
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('host', sa.String(length=255), nullable=False),
        sa.Column('binary', sa.String(length=255), nullable=False),
        sa.Column('topic', sa.String(length=255), nullable=False),
        sa.Column('rpc_version', sa.String(length=36), nullable=True),
        sa.Column('disabled', sa.Boolean(), nullable=False, default=False),
        sa.Column('disabled_reason', sa.String(length=255), nullable=True),
        sa.Column('report_count', sa.Integer(), nullable=False, default=0),
        sa.Column('availability_zone', sa.String(length=255), nullable=True, default='vigie'),
        sa.Column('last_seen_up', sa.DateTime(), nullable=True),
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint('id')
    )

    # Create unique index on host+binary to prevent duplicate service entries
    op.create_index('services_host_binary_idx', 'services', ['host', 'binary'], unique=True)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('services_host_binary_idx', table_name='services')
    op.drop_table('services')
    op.drop_table('tasks')
    # ### end Alembic commands ###
