"""v0.5.2

Revision ID: 74c3d8a361c4
Revises: 9cf68c772527
Create Date: 2026-05-07 17:14:34.302190

"""
from typing import Sequence, Union

import sqlmodel
from alembic import op
import sqlalchemy as sa

import app

# revision identifiers, used by Alembic.
revision: str = '74c3d8a361c4'
down_revision: Union[str, None] = '9cf68c772527'
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! ###
    with op.batch_alter_table('book', schema=None) as batch_op:
        batch_op.add_column(sa.Column('media', app.api.models.base.JSONString(), nullable=True))
        batch_op.add_column(sa.Column('location', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
        batch_op.add_column(sa.Column('isbn', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
        batch_op.add_column(sa.Column('ref_url', sqlmodel.sql.sqltypes.AutoString(), nullable=True))

    with op.batch_alter_table('book_annotation', schema=None) as batch_op:
        batch_op.add_column(sa.Column('style', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
        batch_op.add_column(sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
        batch_op.add_column(sa.Column('note_json', app.api.models.base.JSONString(), nullable=True))
        batch_op.create_index('idx_book_annotation_user_id_book_id', ['user_id', 'book_id'], unique=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('book_annotation', schema=None) as batch_op:
        batch_op.drop_index('idx_book_annotation_user_id_book_id')
        batch_op.drop_column('note_json')
        batch_op.drop_column('title')
        batch_op.drop_column('style')

    with op.batch_alter_table('book', schema=None) as batch_op:
        batch_op.drop_column('ref_url')
        batch_op.drop_column('isbn')
        batch_op.drop_column('location')
        batch_op.drop_column('media')

    # ### end Alembic commands ###
