"""Initial schema for developers and agent_cards

Revision ID: a9d876df1fdf
Revises: 
Create Date: 2025-04-12 07:33:35.434333

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'a9d876df1fdf'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('developers',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('api_key_hash', sa.String(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_developers_id'), 'developers', ['id'], unique=False)
    op.create_index(op.f('ix_developers_name'), 'developers', ['name'], unique=True)
    op.create_table('agent_cards',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('developer_id', sa.Integer(), nullable=False),
    sa.Column('card_data', sa.JSON(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('description', sa.String(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['developer_id'], ['developers.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_agent_cards_description'), 'agent_cards', ['description'], unique=False)
    op.create_index(op.f('ix_agent_cards_developer_id'), 'agent_cards', ['developer_id'], unique=False)
    op.create_index(op.f('ix_agent_cards_is_active'), 'agent_cards', ['is_active'], unique=False)
    op.create_index('ix_agent_cards_name', 'agent_cards', ['name'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_agent_cards_name', table_name='agent_cards')
    op.drop_index(op.f('ix_agent_cards_is_active'), table_name='agent_cards')
    op.drop_index(op.f('ix_agent_cards_developer_id'), table_name='agent_cards')
    op.drop_index(op.f('ix_agent_cards_description'), table_name='agent_cards')
    op.drop_table('agent_cards')
    op.drop_index(op.f('ix_developers_name'), table_name='developers')
    op.drop_index(op.f('ix_developers_id'), table_name='developers')
    op.drop_table('developers')
    # ### end Alembic commands ###
