"""adding invoice table

Revision ID: d718691d4a92
Revises: 968030faf65e
Create Date: 2024-08-01 13:46:29.122991

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'd718691d4a92'
down_revision = '968030faf65e'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('company_plan',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=True),
    sa.Column('plan_id', sa.Integer(), nullable=True),
    sa.Column('start_date', sa.DateTime(), nullable=False),
    sa.Column('end_date', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['company.id'], name=op.f('fk_company_plan_company_id_company')),
    sa.ForeignKeyConstraint(['plan_id'], ['plan.id'], name=op.f('fk_company_plan_plan_id_plan')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_company_plan'))
    )
    with op.batch_alter_table('company', schema=None) as batch_op:
        batch_op.alter_column('name',
               existing_type=sa.VARCHAR(length=120),
               type_=sa.String(length=128),
               existing_nullable=False)
        batch_op.drop_constraint('uq_company_name', type_='unique')
        batch_op.drop_column('updated_at')

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('company', schema=None) as batch_op:
        batch_op.add_column(sa.Column('updated_at', sa.DATETIME(), nullable=True))
        batch_op.create_unique_constraint('uq_company_name', ['name'])
        batch_op.alter_column('name',
               existing_type=sa.String(length=128),
               type_=sa.VARCHAR(length=120),
               existing_nullable=False)

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