"""vendor multiple gstin

Revision ID: 8942aa4774d1
Revises: 435bf9572a7c
Create Date: 2026-05-25 02:52:48.360877

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8942aa4774d1'
down_revision = '435bf9572a7c'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('vendor_gstin',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('vendor_id', sa.Integer(), nullable=False),
    sa.Column('gstin', sa.String(length=20), nullable=False),
    sa.Column('state', sa.String(length=100), nullable=True),
    sa.Column('address', sa.Text(), nullable=True),
    sa.Column('is_default', sa.Boolean(), 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.ForeignKeyConstraint(['company_id'], ['company.id'], ),
    sa.ForeignKeyConstraint(['vendor_id'], ['vendor.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('vendor_id', 'gstin', name='uq_vendor_gstin_vendor_gstin')
    )
    with op.batch_alter_table('vendor_gstin', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_vendor_gstin_company_id'), ['company_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_vendor_gstin_vendor_id'), ['vendor_id'], unique=False)

    with op.batch_alter_table('purchase_invoice', schema=None) as batch_op:
        batch_op.add_column(sa.Column('vendor_gstin_id', sa.Integer(), nullable=True))
        batch_op.add_column(sa.Column('vendor_gstin', sa.String(length=20), nullable=True))
        batch_op.create_index(batch_op.f('ix_purchase_invoice_vendor_gstin_id'), ['vendor_gstin_id'], unique=False)
        batch_op.create_foreign_key(None, 'vendor_gstin', ['vendor_gstin_id'], ['id'])

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('purchase_invoice', schema=None) as batch_op:
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.drop_index(batch_op.f('ix_purchase_invoice_vendor_gstin_id'))
        batch_op.drop_column('vendor_gstin')
        batch_op.drop_column('vendor_gstin_id')

    with op.batch_alter_table('vendor_gstin', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_vendor_gstin_vendor_id'))
        batch_op.drop_index(batch_op.f('ix_vendor_gstin_company_id'))

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