"""add_petty_cash_table Revision ID: 1f0abcdd7300 Revises: 20251003_010501_add_name_to_cash_registers Create Date: 2025-10-04 01:16:30.244567 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '1f0abcdd7300' down_revision = '20251003_010501_add_name_to_cash_registers' branch_labels = None depends_on = None def upgrade() -> None: # Check if table already exists connection = op.get_bind() result = connection.execute(sa.text(""" SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = 'petty_cash' """)).fetchone() if result[0] == 0: op.create_table('petty_cash', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('business_id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False, comment='نام تنخواه گردان'), sa.Column('code', sa.String(length=50), nullable=True, comment='کد یکتا در هر کسب\u200cوکار (اختیاری)'), sa.Column('description', sa.String(length=500), nullable=True), sa.Column('currency_id', sa.Integer(), nullable=False), sa.Column('is_active', sa.Boolean(), server_default=sa.text('1'), nullable=False), sa.Column('is_default', sa.Boolean(), server_default=sa.text('0'), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.ForeignKeyConstraint(['business_id'], ['businesses.id'], ondelete='CASCADE'), sa.ForeignKeyConstraint(['currency_id'], ['currencies.id'], ondelete='RESTRICT'), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('business_id', 'code', name='uq_petty_cash_business_code') ) op.create_index(op.f('ix_petty_cash_business_id'), 'petty_cash', ['business_id'], unique=False) op.create_index(op.f('ix_petty_cash_code'), 'petty_cash', ['code'], unique=False) op.create_index(op.f('ix_petty_cash_currency_id'), 'petty_cash', ['currency_id'], unique=False) op.create_index(op.f('ix_petty_cash_name'), 'petty_cash', ['name'], unique=False) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_index(op.f('ix_petty_cash_name'), table_name='petty_cash') op.drop_index(op.f('ix_petty_cash_currency_id'), table_name='petty_cash') op.drop_index(op.f('ix_petty_cash_code'), table_name='petty_cash') op.drop_index(op.f('ix_petty_cash_business_id'), table_name='petty_cash') op.drop_table('petty_cash') # ### end Alembic commands ###