"""Add buckets to License information

Revision ID: f201bfd23152
Revises: d616ea937a6a
Create Date: 2024-10-03 09:44:32.867470

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'f201bfd23152'
down_revision = 'd616ea937a6a'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('business_event_log', schema=None) as batch_op:
        batch_op.drop_constraint('business_event_log_license_usage_id_fkey', type_='foreignkey')
        batch_op.create_foreign_key(None, 'license_usage', ['license_usage_id'], ['id'], referent_schema='public')

    with op.batch_alter_table('license', schema=None) as batch_op:
        batch_op.add_column(sa.Column('additional_storage_bucket', sa.Integer(), nullable=False))
        batch_op.drop_constraint('license_tier_id_fkey', type_='foreignkey')
        batch_op.drop_constraint('license_tenant_id_fkey', type_='foreignkey')
        batch_op.create_foreign_key(None, 'license_tier', ['tier_id'], ['id'], referent_schema='public')
        batch_op.create_foreign_key(None, 'tenant', ['tenant_id'], ['id'], referent_schema='public')

    with op.batch_alter_table('license_tier', schema=None) as batch_op:
        batch_op.add_column(sa.Column('additional_storage_bucket', sa.Integer(), nullable=False))

    with op.batch_alter_table('license_usage', schema=None) as batch_op:
        batch_op.drop_constraint('license_usage_tenant_id_fkey', type_='foreignkey')
        batch_op.drop_constraint('license_usage_license_id_fkey', type_='foreignkey')
        batch_op.create_foreign_key(None, 'license', ['license_id'], ['id'], referent_schema='public')
        batch_op.create_foreign_key(None, 'tenant', ['tenant_id'], ['id'], referent_schema='public')

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('license_usage', schema=None) as batch_op:
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.create_foreign_key('license_usage_license_id_fkey', 'license', ['license_id'], ['id'])
        batch_op.create_foreign_key('license_usage_tenant_id_fkey', 'tenant', ['tenant_id'], ['id'])

    with op.batch_alter_table('license_tier', schema=None) as batch_op:
        batch_op.drop_column('additional_storage_bucket')

    with op.batch_alter_table('license', schema=None) as batch_op:
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.create_foreign_key('license_tenant_id_fkey', 'tenant', ['tenant_id'], ['id'])
        batch_op.create_foreign_key('license_tier_id_fkey', 'license_tier', ['tier_id'], ['id'])
        batch_op.drop_column('additional_storage_bucket')

    with op.batch_alter_table('business_event_log', schema=None) as batch_op:
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.create_foreign_key('business_event_log_license_usage_id_fkey', 'license_usage', ['license_usage_id'], ['id'])

    # ### end Alembic commands ###
