
"""chnage int to string

Revision ID: cd0160690ac7
Revises: 53752dd97cdd
Create Date: 2025-05-12 22:34:27.200801

"""
from typing import Sequence, Union

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

# revision identifiers, used by Alembic.
revision: str = 'cd0160690ac7'
down_revision: Union[str, None] = '53752dd97cdd'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_admin_users_email', table_name='admin_users')
    op.drop_index('ix_admin_users_id', table_name='admin_users')
    op.drop_table('admin_users')
    op.alter_column('application_users', 'role',
               existing_type=postgresql.ENUM('SUPER_ADMIN', 'SUPPORT_STAFF', 'BILLING_ADMIN', 'admin', 'ADMIN', name='adminroleenum'),
               type_=sa.Enum('SUPER_ADMIN', 'ADMIN', 'SUPPORT_STAFF', 'BILLING_ADMIN', name='applicationuserroleenum'),
               existing_nullable=False)
    op.alter_column('companies', 'id',
               existing_type=sa.INTEGER(),
               type_=sa.String(),
               existing_nullable=False)
    op.alter_column('companies', 'plan',
               existing_type=postgresql.ENUM('FREE', 'STARTER', 'PRO', 'ENTERPRISE', name='planenum'),
               type_=sa.Enum('FREE', 'STARTER', 'PRO', 'ENTERPRISE', name='CompanyPlanEnum'),
               existing_nullable=False)
    op.alter_column('users', 'id',
               existing_type=sa.INTEGER(),
               type_=sa.String(),
               existing_nullable=False)
    op.alter_column('users', 'role',
               existing_type=postgresql.ENUM('ADMIN', 'ANALYST', 'VIEWER', name='roleenum'),
               type_=sa.Enum('ADMIN', 'ANALYST', 'VIEWER', name='companyuserroleenum'),
               existing_nullable=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('users', 'role',
               existing_type=sa.Enum('ADMIN', 'ANALYST', 'VIEWER', name='companyuserroleenum'),
               type_=postgresql.ENUM('ADMIN', 'ANALYST', 'VIEWER', name='roleenum'),
               existing_nullable=False)
    op.alter_column('users', 'id',
               existing_type=sa.String(),
               type_=sa.INTEGER(),
               existing_nullable=False)
    op.alter_column('companies', 'plan',
               existing_type=sa.Enum('FREE', 'STARTER', 'PRO', 'ENTERPRISE', name='CompanyPlanEnum'),
               type_=postgresql.ENUM('FREE', 'STARTER', 'PRO', 'ENTERPRISE', name='planenum'),
               existing_nullable=False)
    op.alter_column('companies', 'id',
               existing_type=sa.String(),
               type_=sa.INTEGER(),
               existing_nullable=False)
    op.alter_column('application_users', 'role',
               existing_type=sa.Enum('SUPER_ADMIN', 'ADMIN', 'SUPPORT_STAFF', 'BILLING_ADMIN', name='applicationuserroleenum'),
               type_=postgresql.ENUM('SUPER_ADMIN', 'SUPPORT_STAFF', 'BILLING_ADMIN', 'admin', 'ADMIN', name='adminroleenum'),
               existing_nullable=False)
    op.create_table('admin_users',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('full_name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('email', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('hashed_password', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('role', postgresql.ENUM('SUPER_ADMIN', 'SUPPORT_STAFF', 'BILLING_ADMIN', 'admin', 'ADMIN', name='adminroleenum'), autoincrement=False, nullable=False),
    sa.Column('is_active', sa.BOOLEAN(), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=True),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name='admin_users_pkey')
    )
    op.create_index('ix_admin_users_id', 'admin_users', ['id'], unique=False)
    op.create_index('ix_admin_users_email', 'admin_users', ['email'], unique=True)
    # ### end Alembic commands ###
