Files
Hotel-Booking/Backend/alembic/versions/d9aff6c5f0d4_add_paypal_payment_method.py
Iliyan Angelov 34b4c969d4 updates
2025-11-19 12:27:01 +02:00

52 lines
1.8 KiB
Python

"""add_paypal_payment_method
Revision ID: d9aff6c5f0d4
Revises: 08e2f866e131
Create Date: 2025-11-19 12:07:50.703320
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = 'd9aff6c5f0d4'
down_revision = '08e2f866e131'
branch_labels = None
depends_on = None
def upgrade() -> None:
# Note: MySQL ENUM modifications can be tricky.
# If payments table already has data with existing enum values,
# we need to preserve them when adding 'paypal'
# For MySQL, we need to alter the ENUM column to include the new value
# Check if we're using MySQL
bind = op.get_bind()
if bind.dialect.name == 'mysql':
# Alter the ENUM column to include 'paypal'
# This preserves existing values and adds 'paypal'
op.execute(
"ALTER TABLE payments MODIFY COLUMN payment_method ENUM('cash', 'credit_card', 'debit_card', 'bank_transfer', 'e_wallet', 'stripe', 'paypal') NOT NULL"
)
else:
# For other databases (PostgreSQL, SQLite), enum changes are handled differently
# For SQLite, this might not be needed as it doesn't enforce enum constraints
pass
# ### end Alembic commands ###
def downgrade() -> None:
# Remove 'paypal' from the ENUM (be careful if there are existing paypal payments)
bind = op.get_bind()
if bind.dialect.name == 'mysql':
# First, check if there are any paypal payments - if so, this will fail
# In production, you'd want to migrate existing paypal payments first
op.execute(
"ALTER TABLE payments MODIFY COLUMN payment_method ENUM('cash', 'credit_card', 'debit_card', 'bank_transfer', 'e_wallet', 'stripe') NOT NULL"
)
# ### end Alembic commands ###