"""add rate_plan_id to bookings

Revision ID: add_rate_plan_id_001
Revises: add_group_booking_001
Create Date: 2024-01-20 00:00:00.000000

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'add_rate_plan_id_001'
down_revision = ('add_group_booking_001', 'add_loyalty_tables_001')
branch_labels = None
depends_on = None


def upgrade() -> None:
    # Add rate_plan_id column to bookings table
    op.add_column('bookings', sa.Column('rate_plan_id', sa.Integer(), nullable=True))
    op.create_foreign_key('fk_bookings_rate_plan', 'bookings', 'rate_plans', ['rate_plan_id'], ['id'], ondelete='SET NULL')
    op.create_index(op.f('ix_bookings_rate_plan_id'), 'bookings', ['rate_plan_id'], unique=False)


def downgrade() -> None:
    # Drop foreign key, index, and column from bookings table
    op.drop_index(op.f('ix_bookings_rate_plan_id'), table_name='bookings')
    op.drop_constraint('fk_bookings_rate_plan', 'bookings', type_='foreignkey')
    op.drop_column('bookings', 'rate_plan_id')

