"""Add semester and phone_number fields to User model

Revision ID: f7d9f10fb52b
Revises: c9784d67f4c7
Create Date: 2025-09-20 21:47:36.770396

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    # Skip dropping vocabulary table since it already exists
    
    with op.batch_alter_table('short_courses', schema=None) as batch_op:
        batch_op.create_foreign_key('fk_short_courses_teacher_id_users', 'users', ['teacher_id'], ['id'])
    
    # Skip dropping indexes that might be needed
    # with op.batch_alter_table('topics', schema=None) as batch_op:
    #     batch_op.drop_index('ix_topics_created_at')
    #     batch_op.drop_index('ix_topics_teacher_id')

    with op.batch_alter_table('users', schema=None) as batch_op:
        batch_op.add_column(sa.Column('semester', sa.Integer(), nullable=True))
        batch_op.add_column(sa.Column('phone_number', sa.String(length=15), nullable=True))

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('users', schema=None) as batch_op:
        batch_op.drop_column('phone_number')
        batch_op.drop_column('semester')

    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)

    with op.batch_alter_table('short_courses', schema=None) as batch_op:
        batch_op.drop_constraint(None, type_='foreignkey')

    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 ###
