"""Add section_title column and adjust nullable constraints in Topic model

Revision ID: 2aecb873ae7d
Revises: f7d9f10fb52b
Create Date: 2025-09-21 03:59:50.776060

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '2aecb873ae7d'
down_revision = 'f7d9f10fb52b'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('vocabulary')
    with op.batch_alter_table('topics', schema=None) as batch_op:
        batch_op.add_column(sa.Column('section_title', sa.String(length=100), nullable=True))
        batch_op.alter_column('category',
               existing_type=sa.VARCHAR(length=50),
               nullable=True)
        batch_op.alter_column('reading_content',
               existing_type=sa.TEXT(),
               nullable=True)
        batch_op.alter_column('teacher_id',
               existing_type=sa.INTEGER(),
               nullable=True)
        batch_op.drop_index('ix_topics_created_at')
        batch_op.drop_index('ix_topics_teacher_id')

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('topics', schema=None) as batch_op:
        batch_op.create_index('ix_topics_teacher_id', ['teacher_id'], unique=False)
        batch_op.create_index('ix_topics_created_at', ['created_at'], unique=False)
        batch_op.alter_column('teacher_id',
               existing_type=sa.INTEGER(),
               nullable=False)
        batch_op.alter_column('reading_content',
               existing_type=sa.TEXT(),
               nullable=False)
        batch_op.alter_column('category',
               existing_type=sa.VARCHAR(length=50),
               nullable=False)
        batch_op.drop_column('section_title')

    op.create_table('vocabulary',
    sa.Column('id', sa.INTEGER(), nullable=True),
    sa.Column('student_id', sa.INTEGER(), nullable=False),
    sa.Column('word', sa.VARCHAR(length=100), nullable=False),
    sa.Column('pronunciation', sa.VARCHAR(length=100), nullable=True),
    sa.Column('definition', sa.TEXT(), nullable=False),
    sa.Column('synonyms', sa.TEXT(), nullable=True),
    sa.Column('antonyms', sa.TEXT(), nullable=True),
    sa.Column('example', sa.TEXT(), nullable=True),
    sa.Column('date_added', sa.DATETIME(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
    sa.ForeignKeyConstraint(['student_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###
