"""make user model auth0 friendly

Revision ID: f40166b201f1
Revises: e2819d7d0588
Create Date: 2025-04-22 07:39:32.814357

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'f40166b201f1'
down_revision = 'e2819d7d0588'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('chat_sync_id_fkey', 'chat', type_='foreignkey')
    op.create_foreign_key(None, 'chat', 'sync', ['sync_id'], ['id'])
    op.drop_constraint('sync_connection_sync_id_fkey', 'sync_connection', type_='foreignkey')
    op.create_foreign_key(None, 'sync_connection', 'sync', ['sync_id'], ['id'])
    op.add_column('user', sa.Column('auth0_id', sa.String(), nullable=True))
    op.alter_column('user', 'full_name',
               existing_type=sa.VARCHAR(),
               nullable=True)
    op.create_unique_constraint(None, 'user', ['auth0_id'])
    op.drop_column('user', 'password')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('user', sa.Column('password', sa.VARCHAR(), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'user', type_='unique')
    op.alter_column('user', 'full_name',
               existing_type=sa.VARCHAR(),
               nullable=False)
    op.drop_column('user', 'auth0_id')
    op.drop_constraint(None, 'sync_connection', type_='foreignkey')
    op.create_foreign_key('sync_connection_sync_id_fkey', 'sync_connection', 'sync', ['sync_id'], ['id'], ondelete='CASCADE')
    op.drop_constraint(None, 'chat', type_='foreignkey')
    op.create_foreign_key('chat_sync_id_fkey', 'chat', 'sync', ['sync_id'], ['id'], ondelete='CASCADE')
    # ### end Alembic commands ###
