"""Corrections on Licensing models

Revision ID: d616ea937a6a
Revises: 560d08d91e5b
Create Date: 2024-10-02 15:39:27.668741

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'd616ea937a6a'
down_revision = '560d08d91e5b'
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.drop_constraint('license_tenant_id_fkey', type_='foreignkey')
        batch_op.drop_constraint('license_tier_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_usage', schema=None) as batch_op:
        batch_op.drop_constraint('license_usage_license_id_fkey', type_='foreignkey')
        batch_op.drop_constraint('license_usage_tenant_id_fkey', type_='foreignkey')
        batch_op.create_foreign_key(None, 'tenant', ['tenant_id'], ['id'], referent_schema='public')
        batch_op.create_foreign_key(None, 'license', ['license_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_tenant_id_fkey', 'tenant', ['tenant_id'], ['id'])
        batch_op.create_foreign_key('license_usage_license_id_fkey', 'license', ['license_id'], ['id'])

    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_tier_id_fkey', 'license_tier', ['tier_id'], ['id'])
        batch_op.create_foreign_key('license_tenant_id_fkey', 'tenant', ['tenant_id'], ['id'])

    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 ###
