"""Updating Tenant, User and TenantProject to cope with new authentication mechanism

Revision ID: 392d48aa045e
Revises: 51aba07aac6b
Create Date: 2024-11-20 14:23:28.742766

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '392d48aa045e'
down_revision = '51aba07aac6b'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('tenant', schema=None) as batch_op:
        batch_op.drop_column('encrypted_chat_api_key')
        batch_op.drop_column('encrypted_api_key')
        batch_op.drop_column('fallback_algorithms')
        batch_op.drop_column('usage_email')

    with op.batch_alter_table('tenant_project', schema=None) as batch_op:
        batch_op.add_column(sa.Column('responsible_email', sa.String(length=255), nullable=True))

    with op.batch_alter_table('user', schema=None) as batch_op:
        batch_op.add_column(sa.Column('is_primary_contact', sa.Boolean(), nullable=True))
        batch_op.add_column(sa.Column('is_financial_contact', sa.Boolean(), nullable=True))

    # ### end Alembic commands ###


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

    with op.batch_alter_table('tenant_project', schema=None) as batch_op:
        batch_op.drop_column('responsible_email')

    with op.batch_alter_table('tenant', schema=None) as batch_op:
        batch_op.add_column(sa.Column('usage_email', sa.VARCHAR(length=255), autoincrement=False, nullable=True))
        batch_op.add_column(sa.Column('fallback_algorithms', postgresql.ARRAY(sa.VARCHAR(length=50)), autoincrement=False, nullable=True))
        batch_op.add_column(sa.Column('encrypted_api_key', sa.VARCHAR(length=500), autoincrement=False, nullable=True))
        batch_op.add_column(sa.Column('encrypted_chat_api_key', sa.VARCHAR(length=500), autoincrement=False, nullable=True))

    # ### end Alembic commands ###
