"""add customer vendor party module

Revision ID: 5fdb57ca1f09
Revises: c7e6acd03cbd
Create Date: 2026-04-25 11:41:17.109733

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '5fdb57ca1f09'
down_revision = 'c7e6acd03cbd'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('customer',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('customer_code', sa.String(length=30), nullable=False),
    sa.Column('customer_name', sa.String(length=150), nullable=False),
    sa.Column('ledger_id', sa.Integer(), nullable=False),
    sa.Column('contact_person', sa.String(length=150), nullable=True),
    sa.Column('mobile', sa.String(length=20), nullable=True),
    sa.Column('email', sa.String(length=150), nullable=True),
    sa.Column('billing_address', sa.Text(), nullable=True),
    sa.Column('shipping_address', sa.Text(), nullable=True),
    sa.Column('city', sa.String(length=100), nullable=True),
    sa.Column('state', sa.String(length=100), nullable=True),
    sa.Column('country', sa.String(length=100), nullable=True),
    sa.Column('pincode', sa.String(length=20), nullable=True),
    sa.Column('gstin', sa.String(length=20), nullable=True),
    sa.Column('pan', sa.String(length=20), nullable=True),
    sa.Column('credit_limit', sa.Numeric(precision=14, scale=2), nullable=False),
    sa.Column('credit_days', sa.Integer(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('is_deleted', sa.Boolean(), nullable=False),
    sa.Column('deleted_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['company.id'], ),
    sa.ForeignKeyConstraint(['ledger_id'], ['account_ledger.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('company_id', 'customer_code', name='uq_customer_company_code'),
    sa.UniqueConstraint('company_id', 'ledger_id', name='uq_customer_company_ledger')
    )
    with op.batch_alter_table('customer', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_customer_company_id'), ['company_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_customer_ledger_id'), ['ledger_id'], unique=False)

    op.create_table('vendor',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('vendor_code', sa.String(length=30), nullable=False),
    sa.Column('vendor_name', sa.String(length=150), nullable=False),
    sa.Column('ledger_id', sa.Integer(), nullable=False),
    sa.Column('contact_person', sa.String(length=150), nullable=True),
    sa.Column('mobile', sa.String(length=20), nullable=True),
    sa.Column('email', sa.String(length=150), nullable=True),
    sa.Column('billing_address', sa.Text(), nullable=True),
    sa.Column('city', sa.String(length=100), nullable=True),
    sa.Column('state', sa.String(length=100), nullable=True),
    sa.Column('country', sa.String(length=100), nullable=True),
    sa.Column('pincode', sa.String(length=20), nullable=True),
    sa.Column('gstin', sa.String(length=20), nullable=True),
    sa.Column('pan', sa.String(length=20), nullable=True),
    sa.Column('payment_terms_days', sa.Integer(), nullable=False),
    sa.Column('credit_limit', sa.Numeric(precision=14, scale=2), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('is_deleted', sa.Boolean(), nullable=False),
    sa.Column('deleted_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['company.id'], ),
    sa.ForeignKeyConstraint(['ledger_id'], ['account_ledger.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('company_id', 'ledger_id', name='uq_vendor_company_ledger'),
    sa.UniqueConstraint('company_id', 'vendor_code', name='uq_vendor_company_code')
    )
    with op.batch_alter_table('vendor', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_vendor_company_id'), ['company_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_vendor_ledger_id'), ['ledger_id'], unique=False)

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('vendor', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_vendor_ledger_id'))
        batch_op.drop_index(batch_op.f('ix_vendor_company_id'))

    op.drop_table('vendor')
    with op.batch_alter_table('customer', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_customer_ledger_id'))
        batch_op.drop_index(batch_op.f('ix_customer_company_id'))

    op.drop_table('customer')
    # ### end Alembic commands ###
