"""Add core enhancements

Revision ID: a0b7abe57112
Revises: c26cc8212061
Create Date: 2025-12-02 01:33:56.476865

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import sqlmodel


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


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('artist',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('instrument', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_artist_name'), 'artist', ['name'], unique=False)
    op.create_table('tag',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_tag_name'), 'tag', ['name'], unique=True)
    op.create_index(op.f('ix_tag_slug'), 'tag', ['slug'], unique=True)
    op.create_table('tour',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('start_date', sa.DateTime(), nullable=True),
    sa.Column('end_date', sa.DateTime(), nullable=True),
    sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_tour_name'), 'tour', ['name'], unique=False)
    op.create_table('entitytag',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('tag_id', sa.Integer(), nullable=False),
    sa.Column('entity_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('entity_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_entitytag_entity_id'), 'entitytag', ['entity_id'], unique=False)
    op.create_index(op.f('ix_entitytag_entity_type'), 'entitytag', ['entity_type'], unique=False)
    op.create_table('attendance',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('show_id', sa.Integer(), nullable=False),
    sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['show_id'], ['show.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('showartist',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('show_id', sa.Integer(), nullable=False),
    sa.Column('artist_id', sa.Integer(), nullable=False),
    sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.ForeignKeyConstraint(['artist_id'], ['artist.id'], ),
    sa.ForeignKeyConstraint(['show_id'], ['show.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('performanceartist',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('performance_id', sa.Integer(), nullable=False),
    sa.Column('artist_id', sa.Integer(), nullable=False),
    sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.ForeignKeyConstraint(['artist_id'], ['artist.id'], ),
    sa.ForeignKeyConstraint(['performance_id'], ['performance.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('show', schema=None) as batch_op:
        batch_op.add_column(sa.Column('tour_id', sa.Integer(), nullable=True))
        batch_op.add_column(sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
        batch_op.create_foreign_key('fk_show_tour', 'tour', ['tour_id'], ['id'])

    with op.batch_alter_table('song', schema=None) as batch_op:
        batch_op.add_column(sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True))

    with op.batch_alter_table('venue', schema=None) as batch_op:
        batch_op.add_column(sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('venue', 'notes')
    op.drop_column('song', 'notes')
    op.drop_constraint(None, 'show', type_='foreignkey')
    op.drop_column('show', 'notes')
    op.drop_column('show', 'tour_id')
    op.drop_table('performanceartist')
    op.drop_table('showartist')
    op.drop_table('attendance')
    op.drop_index(op.f('ix_entitytag_entity_type'), table_name='entitytag')
    op.drop_index(op.f('ix_entitytag_entity_id'), table_name='entitytag')
    op.drop_table('entitytag')
    op.drop_index(op.f('ix_tour_name'), table_name='tour')
    op.drop_table('tour')
    op.drop_index(op.f('ix_tag_slug'), table_name='tag')
    op.drop_index(op.f('ix_tag_name'), table_name='tag')
    op.drop_table('tag')
    op.drop_index(op.f('ix_artist_name'), table_name='artist')
    op.drop_table('artist')
    # ### end Alembic commands ###
