"""Clean initial setup

Revision ID: 4235c46360a8
Revises: e986eff3341b
Create Date: 2025-09-03 03:19:06.901004

"""
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 = '4235c46360a8'
down_revision: Union[str, None] = 'e986eff3341b'
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_table('role_department_permissions')
    # op.drop_table('user_roles')
    # op.drop_table('application_users')
    # op.drop_table('employees')
    # op.drop_table('email_notification_settings')
    # op.drop_index(op.f('ix_budget_lines_id'), table_name='budget_lines')
    # op.drop_table('budget_lines')
    op.drop_index(op.f('ix_companies_db_name'), table_name='companies')
    op.drop_index(op.f('ix_companies_email'), table_name='companies')
    op.drop_index(op.f('ix_companies_id'), table_name='companies')
    # op.drop_table('companies')
    # op.drop_table('ip_addresses')
    # op.drop_table('subscription_plans')
    # op.drop_index(op.f('ix_tickets_ticket_id'), table_name='tickets')
    # op.drop_table('tickets')
    # op.drop_index(op.f('ix_crm_opportunity_id'), table_name='crm')
    # op.drop_table('crm')
    # op.drop_table('derived_metric')
    # op.drop_index(op.f('ix_general_ledger_id'), table_name='general_ledger')
    # op.drop_index(op.f('ix_general_ledger_transaction_hash'), table_name='general_ledger')
    # op.drop_table('general_ledger')
    # op.drop_table('metric_definition')
    # op.drop_table('modules')
    # op.drop_index(op.f('ix_forecast_scenarios_id'), table_name='forecast_scenarios')
    # op.drop_table('forecast_scenarios')
    # op.drop_table('hr_integration_history')
    # op.drop_table('file_upload_history')
    # op.drop_table('role_department')
    # op.drop_table('general_ledger_entries')
    # op.drop_table('departments')
    # op.drop_index(op.f('ix_users_email'), table_name='users')
    # op.drop_index(op.f('ix_users_id'), table_name='users')
    # op.drop_table('users')
    # op.drop_table('appearance_theme_settings')
    # op.drop_index(op.f('ix_forecast_data_id'), table_name='forecast_data')
    # op.drop_table('forecast_data')
    # op.drop_table('crm_integration_history')
    # op.drop_index(op.f('ix_forecast_clients_id'), table_name='forecast_clients')
    # op.drop_table('forecast_clients')
    # op.drop_table('Financial_widget')
    # op.drop_table('roles')
    # op.drop_table('attribute')
    # op.drop_index(op.f('ix_budget_versions_id'), table_name='budget_versions')
    # op.drop_table('budget_versions')
    # op.drop_table('entity')
    # op.drop_table('plan_modules')
    # op.drop_table('value')
    # op.drop_table('permissions')
    # op.drop_table('integration_history')
    # op.drop_index(op.f('ix_forecast_versions_id'), table_name='forecast_versions')
    # op.drop_table('forecast_versions')
    # op.drop_table('subscriptions')
    # op.drop_index(op.f('ix_forecast_expenses_id'), table_name='forecast_expenses')
    # op.drop_table('forecast_expenses')
    # op.drop_table('attachments')
    # op.drop_table('tracked_json_keys')
    # op.drop_index(op.f('ix_general_ledger_master_id'), table_name='general_ledger_master')
    # op.drop_table('general_ledger_master')
    # op.drop_index(op.f('ix_corporate_guidelines_id'), table_name='corporate_guidelines')
    # op.drop_table('corporate_guidelines')
    # op.drop_index(op.f('ix_CRM_opportunity_id'), table_name='CRM')
    # op.drop_table('CRM')
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('CRM',
    sa.Column('opportunity_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('customer_name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('contact_person', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('email', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('product', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('deal_amount', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False),
    sa.Column('stage', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('probability', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('expected_close_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('region', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('extra_data', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=True),
    sa.Column('user_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('opportunity_id', name=op.f('CRM_pkey'))
    )
    op.create_index(op.f('ix_CRM_opportunity_id'), 'CRM', ['opportunity_id'], unique=False)
    op.create_table('corporate_guidelines',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('fiscal_year', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('description', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('rule', sa.VARCHAR(), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('corporate_guidelines_pkey'))
    )
    op.create_index(op.f('ix_corporate_guidelines_id'), 'corporate_guidelines', ['id'], unique=False)
    op.create_table('general_ledger_master',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('general_ledger_code', sa.NUMERIC(precision=50, scale=0), autoincrement=False, nullable=False),
    sa.Column('account_name', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('category', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
    sa.Column('tags', postgresql.ARRAY(sa.VARCHAR()), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('general_ledger_master_pkey')),
    sa.UniqueConstraint('general_ledger_code', name=op.f('general_ledger_master_general_ledger_code_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_index(op.f('ix_general_ledger_master_id'), 'general_ledger_master', ['id'], unique=False)
    op.create_table('tracked_json_keys',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('table_name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('column_name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('key', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('created_at', postgresql.TIMESTAMP(), server_default=sa.text('now()'), autoincrement=False, nullable=True),
    sa.Column('has_null_values', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('data_type', sa.VARCHAR(), autoincrement=False, nullable=True),
    sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('tracked_json_keys_pkey')),
    sa.UniqueConstraint('key', name=op.f('tracked_json_keys_key_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_table('attachments',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('ticket_id', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('file_path', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('uploaded_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['ticket_id'], ['tickets.id'], name=op.f('attachments_ticket_id_fkey')),
    sa.PrimaryKeyConstraint('id', name=op.f('attachments_pkey'))
    )
    op.create_table('forecast_expenses',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('scenario_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('department', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('type', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('prev_month', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month1_ai', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month1_adjusted', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month2_ai', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month2_adjusted', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month3_ai', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month3_adjusted', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['scenario_id'], ['forecast_scenarios.id'], name=op.f('forecast_expenses_scenario_id_fkey'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id', name=op.f('forecast_expenses_pkey'))
    )
    op.create_index(op.f('ix_forecast_expenses_id'), 'forecast_expenses', ['id'], unique=False)
    op.create_table('subscriptions',
    sa.Column('id', sa.BIGINT(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('plan_id', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('collaborators', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('business_users', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('view_only', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('price', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('start_date', sa.DATE(), autoincrement=False, nullable=False),
    sa.Column('end_date', sa.DATE(), autoincrement=False, nullable=True),
    sa.Column('status', sa.VARCHAR(length=20), autoincrement=False, nullable=True),
    sa.Column('create_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], name=op.f('fk_user_company')),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], name=op.f('subscriptions_company_id_fkey')),
    sa.ForeignKeyConstraint(['plan_id'], ['subscription_plans.id'], name=op.f('subscriptions_plan_id_fkey')),
    sa.PrimaryKeyConstraint('id', name=op.f('subscriptions_pkey'))
    )
    op.create_table('forecast_versions',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('scenario_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('version_number', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=True),
    sa.Column('data', sa.VARCHAR(), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['scenario_id'], ['forecast_scenarios.id'], name=op.f('forecast_versions_scenario_id_fkey')),
    sa.PrimaryKeyConstraint('id', name=op.f('forecast_versions_pkey'))
    )
    op.create_index(op.f('ix_forecast_versions_id'), 'forecast_versions', ['id'], unique=False)
    op.create_table('integration_history',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('source_type', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
    sa.Column('source_identifier', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
    sa.Column('status', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
    sa.Column('message', sa.VARCHAR(length=1000), autoincrement=False, nullable=True),
    sa.Column('uploaded_user_id', sa.UUID(), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name='integration_history_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_table('permissions',
    sa.Column('id', sa.BIGINT(), server_default=sa.text("nextval('permissions_id_seq'::regclass)"), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('module_id', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('create_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['module_id'], ['modules.id'], name='permissions_module_id_fkey', ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id', name='permissions_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_table('value',
    sa.Column('value_id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('entity_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('attribute_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('value', sa.TEXT(), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['attribute_id'], ['attribute.attribute_id'], name=op.f('value_attribute_id_fkey')),
    sa.ForeignKeyConstraint(['entity_id'], ['entity.entity_id'], name=op.f('value_entity_id_fkey')),
    sa.PrimaryKeyConstraint('value_id', name=op.f('value_pkey'))
    )
    op.create_table('plan_modules',
    sa.Column('plan_id', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('module_id', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('create_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['module_id'], ['modules.id'], name=op.f('plan_modules_module_id_fkey'), ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['plan_id'], ['subscription_plans.id'], name=op.f('plan_modules_plan_id_fkey'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('plan_id', 'module_id', name=op.f('plan_modules_pkey'))
    )
    op.create_table('entity',
    sa.Column('entity_id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('entity_id', name=op.f('entity_pkey'))
    )
    op.create_table('budget_versions',
    sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('budget_versions_id_seq'::regclass)"), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('fiscal_year', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('status', postgresql.ENUM('draft', 'submitted', 'approved', 'rejected', name='budgetstatus'), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name='budget_versions_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_index(op.f('ix_budget_versions_id'), 'budget_versions', ['id'], unique=False)
    op.create_table('attribute',
    sa.Column('attribute_id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('attribute_id', name=op.f('attribute_pkey')),
    sa.UniqueConstraint('name', name=op.f('attribute_name_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_table('roles',
    sa.Column('id', sa.BIGINT(), server_default=sa.text("nextval('roles_id_seq'::regclass)"), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('create_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name='roles_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_table('Financial_widget',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('category', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('chart_Type', postgresql.ENUM('BAR_CHART', 'LINE_CHART', 'PIE_CHART', 'DOUGHNUT_CHART', 'BUBBLE_CHART', 'AREA_CHART', 'RADAR_CHART', name='charttypeenum'), autoincrement=False, nullable=False),
    sa.Column('enable_or_disable', sa.BOOLEAN(), autoincrement=False, nullable=True),
    sa.Column('position', sa.INTEGER(), autoincrement=False, nullable=False),
    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), server_default=sa.text('now()'), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('Financial_widget_pkey')),
    sa.UniqueConstraint('name', name=op.f('Financial_widget_name_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_table('forecast_clients',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('scenario_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('client_name', sa.VARCHAR(), autoincrement=False, nullable=True),
    sa.Column('previous_month', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month1_ai', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month1_user', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month2_ai', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month2_user', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month3_ai', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('month3_user', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['scenario_id'], ['forecast_scenarios.id'], name=op.f('forecast_clients_scenario_id_fkey')),
    sa.PrimaryKeyConstraint('id', name=op.f('forecast_clients_pkey'))
    )
    op.create_index(op.f('ix_forecast_clients_id'), 'forecast_clients', ['id'], unique=False)
    op.create_table('crm_integration_history',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('source_type', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
    sa.Column('source_identifier', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
    sa.Column('status', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
    sa.Column('message', sa.VARCHAR(length=1000), autoincrement=False, nullable=True),
    sa.Column('uploaded_user_id', sa.UUID(), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name='crm_integration_history_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_table('forecast_data',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('year', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('quarter', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('scenario', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('metric_type', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('is_ai', sa.BOOLEAN(), autoincrement=False, nullable=True),
    sa.Column('value', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('forecast_data_pkey')),
    sa.UniqueConstraint('year', 'quarter', 'scenario', 'metric_type', 'is_ai', name=op.f('uq_forecast_entry'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_index(op.f('ix_forecast_data_id'), 'forecast_data', ['id'], unique=False)
    op.create_table('appearance_theme_settings',
    sa.Column('id', sa.BIGINT(), autoincrement=True, nullable=False),
    sa.Column('primary_color', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('background_color', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('font_color', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('font_size', postgresql.ENUM('SMALL', 'MEDIUM', 'LARGE', name='fontsizeenum'), autoincrement=False, nullable=False),
    sa.Column('font_family', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('company_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('appearance_theme_settings_pkey')),
    sa.UniqueConstraint('company_id', name=op.f('appearance_theme_settings_company_id_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_table('users',
    sa.Column('id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('company_name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('company_id', sa.VARCHAR(), autoincrement=False, 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('is_2FA_required', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('is_2FA_enabled', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('temp_2fa_secret', sa.VARCHAR(length=100), autoincrement=False, nullable=True),
    sa.Column('secret_2fa', sa.VARCHAR(length=100), autoincrement=False, nullable=True),
    sa.Column('department', postgresql.ENUM('HR', 'FINANCE', 'MARKETING', 'SALES', 'CEO', 'CFO', 'ADMINISTRATION', 'IT', name='departmentenum'), autoincrement=False, nullable=False),
    sa.Column('role', postgresql.ENUM('ADMIN', 'ANALYST', 'VIEWER', name='companyuserroleenum'), autoincrement=False, nullable=False),
    sa.Column('permissions', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True),
    sa.Column('system_password_reset', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('password_reset_token', sa.VARCHAR(length=512), autoincrement=False, nullable=True),
    sa.Column('is_active', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
    sa.Column('deleted_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name='users_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_table('departments',
    sa.Column('id', sa.BIGINT(), server_default=sa.text("nextval('departments_id_seq'::regclass)"), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('create_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name='departments_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_table('general_ledger_entries',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('posting_date', sa.DATE(), autoincrement=False, nullable=False),
    sa.Column('amount', sa.NUMERIC(precision=15, scale=2), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('general_ledger_entries_pkey'))
    )
    op.create_table('role_department',
    sa.Column('id', sa.BIGINT(), server_default=sa.text("nextval('role_department_id_seq'::regclass)"), autoincrement=True, nullable=False),
    sa.Column('role_id', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('department_id', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('create_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], name='role_department_department_id_fkey', ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], name='role_department_role_id_fkey', ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id', name='role_department_pkey'),
    sa.UniqueConstraint('role_id', 'department_id', name='_role_department_uc', postgresql_include=[], postgresql_nulls_not_distinct=False),
    postgresql_ignore_search_path=False
    )
    op.create_table('file_upload_history',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('file_name', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('file_path', sa.VARCHAR(length=512), autoincrement=False, nullable=False),
    sa.Column('file_type', sa.VARCHAR(length=50), autoincrement=False, nullable=True),
    sa.Column('uploaded_by', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('uploaded_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('status', sa.VARCHAR(length=50), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('file_upload_history_pkey'))
    )
    op.create_table('hr_integration_history',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('source_type', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
    sa.Column('source_identifier', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
    sa.Column('status', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
    sa.Column('message', sa.VARCHAR(length=1000), autoincrement=False, nullable=True),
    sa.Column('uploaded_user_id', sa.UUID(), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('hr_integration_history_pkey'))
    )
    op.create_table('forecast_scenarios',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=True),
    sa.Column('user_id', sa.VARCHAR(), autoincrement=False, nullable=True),
    sa.Column('assumptions', sa.VARCHAR(), 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.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('forecast_scenarios_user_id_fkey')),
    sa.PrimaryKeyConstraint('id', name=op.f('forecast_scenarios_pkey'))
    )
    op.create_index(op.f('ix_forecast_scenarios_id'), 'forecast_scenarios', ['id'], unique=False)
    op.create_table('modules',
    sa.Column('id', sa.BIGINT(), server_default=sa.text("nextval('modules_id_seq'::regclass)"), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('create_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name='modules_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_table('metric_definition',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('tags', postgresql.ARRAY(sa.VARCHAR()), autoincrement=False, nullable=True),
    sa.Column('gl_codes', postgresql.ARRAY(sa.NUMERIC(precision=50, scale=0)), autoincrement=False, nullable=True),
    sa.Column('amount_field', sa.VARCHAR(length=10), 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), server_default=sa.text('now()'), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('metric_definition_pkey')),
    sa.UniqueConstraint('name', name=op.f('metric_definition_name_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_table('general_ledger',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('general_ledger_code', sa.NUMERIC(precision=50, scale=0), autoincrement=False, nullable=False),
    sa.Column('account_name', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('category', sa.VARCHAR(length=50), autoincrement=False, nullable=True),
    sa.Column('description', sa.VARCHAR(length=500), autoincrement=False, nullable=True),
    sa.Column('debit', sa.NUMERIC(precision=15, scale=2), autoincrement=False, nullable=False),
    sa.Column('credit', sa.NUMERIC(precision=15, scale=2), autoincrement=False, nullable=False),
    sa.Column('is_active', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('entry_by', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('entry_system_source', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('transaction_hash', sa.VARCHAR(), autoincrement=False, nullable=True),
    sa.Column('integration_id', sa.UUID(), autoincrement=False, nullable=True),
    sa.Column('extra_data', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['integration_id'], ['integration_history.id'], name=op.f('general_ledger_integration_id_fkey'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id', name=op.f('general_ledger_pkey'))
    )
    op.create_index(op.f('ix_general_ledger_transaction_hash'), 'general_ledger', ['transaction_hash'], unique=True)
    op.create_index(op.f('ix_general_ledger_id'), 'general_ledger', ['id'], unique=False)
    op.create_table('derived_metric',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('formula', sa.VARCHAR(length=500), autoincrement=False, nullable=False),
    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), server_default=sa.text('now()'), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('derived_metric_pkey')),
    sa.UniqueConstraint('name', name=op.f('derived_metric_name_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_table('crm',
    sa.Column('opportunity_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('integration_id', sa.UUID(), autoincrement=False, nullable=True),
    sa.Column('customer_name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('contact_person', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('email', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('product', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('deal_amount', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False),
    sa.Column('stage', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('probability', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('expected_close_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('region', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('extra_data', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=True),
    sa.Column('user_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['integration_id'], ['crm_integration_history.id'], name=op.f('crm_integration_id_fkey'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('opportunity_id', name=op.f('crm_pkey'))
    )
    op.create_index(op.f('ix_crm_opportunity_id'), 'crm', ['opportunity_id'], unique=False)
    op.create_table('tickets',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('ticket_id', sa.VARCHAR(), autoincrement=False, nullable=True),
    sa.Column('company_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('user_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('email', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('issue_type', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('title', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('description', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('priority', postgresql.ENUM('LOW', 'MEDIUM', 'HIGH', 'CRITICAL', name='ticketpriorityenum'), autoincrement=False, nullable=False),
    sa.Column('status', postgresql.ENUM('OPEN', 'IN_PROGRESS', 'RESOLVED', 'CLOSED', name='ticketstatusenum'), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('tickets_pkey'))
    )
    op.create_index(op.f('ix_tickets_ticket_id'), 'tickets', ['ticket_id'], unique=True)
    op.create_table('subscription_plans',
    sa.Column('id', sa.BIGINT(), autoincrement=True, nullable=False),
    sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('billing_cycle', postgresql.ENUM('monthly', 'yearly', 'custom', name='billingcycle'), autoincrement=False, nullable=False),
    sa.Column('price', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('collaborators', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('business_users', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('view_only', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('user_limit', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('create_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('subscription_plans_pkey'))
    )
    op.create_table('ip_addresses',
    sa.Column('id', sa.BIGINT(), autoincrement=True, nullable=False),
    sa.Column('company_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('allowed_ipaddress', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name=op.f('ip_addresses_pkey'))
    )
    op.create_table('companies',
    sa.Column('id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('company_name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('legal_name', sa.VARCHAR(length=150), autoincrement=False, nullable=True),
    sa.Column('bio', sa.VARCHAR(length=500), autoincrement=False, nullable=True),
    sa.Column('address', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('home_country', sa.VARCHAR(length=100), autoincrement=False, nullable=True),
    sa.Column('company_logo_url', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
    sa.Column('has_branches', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('users_count', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('email', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
    sa.Column('phone_number', sa.VARCHAR(length=20), autoincrement=False, nullable=True),
    sa.Column('db_name', sa.VARCHAR(length=100), autoincrement=False, nullable=True),
    sa.Column('db_host', sa.VARCHAR(length=100), autoincrement=False, nullable=True),
    sa.Column('db_port', sa.VARCHAR(length=6), autoincrement=False, nullable=True),
    sa.Column('is_2FA_enabled', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('plan', postgresql.ENUM('BASIC', 'PROFICIENT', 'EXPERIENCED', name='companyplanenum'), autoincrement=False, nullable=False),
    sa.Column('trial_ends_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
    sa.Column('next_billing_date', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
    sa.Column('is_active', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('settings', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
    sa.Column('deleted_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name='companies_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_index(op.f('ix_companies_id'), 'companies', ['id'], unique=False)
    op.create_index(op.f('ix_companies_email'), 'companies', ['email'], unique=True)
    op.create_index(op.f('ix_companies_db_name'), 'companies', ['db_name'], unique=True)
    op.create_table('budget_lines',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('version_id', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('account_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('department_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('driver', sa.VARCHAR(), autoincrement=False, nullable=True),
    sa.Column('monthly_values', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['version_id'], ['budget_versions.id'], name=op.f('budget_lines_version_id_fkey')),
    sa.PrimaryKeyConstraint('id', name=op.f('budget_lines_pkey'))
    )
    op.create_index(op.f('ix_budget_lines_id'), 'budget_lines', ['id'], unique=False)
    op.create_table('email_notification_settings',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('user_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('transaction_alert', sa.BOOLEAN(), autoincrement=False, nullable=True),
    sa.Column('report_ready', sa.BOOLEAN(), autoincrement=False, nullable=True),
    sa.Column('system_update', sa.BOOLEAN(), autoincrement=False, nullable=True),
    sa.Column('weekly_summary', sa.BOOLEAN(), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('email_notification_settings_user_id_fkey')),
    sa.PrimaryKeyConstraint('id', name=op.f('email_notification_settings_pkey')),
    sa.UniqueConstraint('user_id', name=op.f('email_notification_settings_user_id_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_table('employees',
    sa.Column('employee_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('email', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('job_title', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('department', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('start_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('termination_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('base_salary', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False),
    sa.Column('bonus', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('status', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('location', sa.VARCHAR(), autoincrement=False, nullable=True),
    sa.Column('extra_data', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=True),
    sa.Column('user_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('employee_id', name=op.f('employees_pkey'))
    )
    op.create_table('application_users',
    sa.Column('id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('email', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('hashed_password', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('full_name', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('role', postgresql.ENUM('SUPER_ADMIN', 'ADMIN', 'SUPPORT_STAFF', 'BILLING_ADMIN', name='applicationuserroleenum'), autoincrement=False, nullable=False),
    sa.Column('is_account_active', sa.BOOLEAN(), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
    sa.Column('is_2FA_required', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('is_2FA_enabled', sa.BOOLEAN(), autoincrement=False, nullable=False),
    sa.Column('temp_2fa_secret', sa.VARCHAR(length=100), autoincrement=False, nullable=True),
    sa.Column('secret_2fa', sa.VARCHAR(length=100), autoincrement=False, nullable=True),
    sa.Column('failed_login_attempts', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('is_account_locked', sa.BOOLEAN(), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('application_users_pkey')),
    sa.UniqueConstraint('email', name=op.f('application_users_email_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_table('user_roles',
    sa.Column('id', sa.BIGINT(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('role_department_id', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('company_id', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('create_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['company_id'], ['companies.id'], name=op.f('user_roles_company_id_fkey'), ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['role_department_id'], ['role_department.id'], name=op.f('user_roles_role_department_id_fkey'), ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('user_roles_user_id_fkey'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id', name=op.f('user_roles_pkey')),
    sa.UniqueConstraint('user_id', 'role_department_id', 'company_id', name=op.f('_user_role_uc'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    op.create_table('role_department_permissions',
    sa.Column('id', sa.BIGINT(), autoincrement=True, nullable=False),
    sa.Column('role_department_id', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('permission_id', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('create_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['permission_id'], ['permissions.id'], name=op.f('role_department_permissions_permission_id_fkey'), ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['role_department_id'], ['role_department.id'], name=op.f('role_department_permissions_role_department_id_fkey'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id', name=op.f('role_department_permissions_pkey')),
    sa.UniqueConstraint('role_department_id', 'permission_id', name=op.f('_rd_permission_uc'), postgresql_include=[], postgresql_nulls_not_distinct=False)
    )
    # ### end Alembic commands ###
