"""Add user authentication fields

Revision ID: 1c297825e3a9
Revises: 
Create Date: 2025-06-02 13:26:30.353000

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect


# revision identifiers, used by Alembic.
revision = '1c297825e3a9'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # Check if the table exists before creating it
    conn = op.get_bind()
    inspector = sa.inspect(conn)
    if 'user' not in inspector.get_table_names():
        conn = op.get_bind()
        inspector = inspect(conn)
        tables = inspector.get_table_names()
        
        if 'user' not in tables:
            op.create_table('user',
                sa.Column('id', sa.Integer(), nullable=False),
                sa.Column('username', sa.String(length=150), nullable=False),
                sa.Column('email', sa.String(length=150), nullable=False),
                sa.Column('password_hash', sa.String(length=128), nullable=True),
                sa.PrimaryKeyConstraint('id'),
                sa.UniqueConstraint('email'),
                sa.UniqueConstraint('username')
            )


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user')
    # ### end Alembic commands ### 