55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
"""Add offer display fields to hotel groups.
|
|
|
|
Revision ID: 0006_hotel_group_offer_fields
|
|
Revises: 0005_hotel_vehicle_modules
|
|
Create Date: 2026-07-03
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy import inspect
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
|
|
revision = "0006_hotel_group_offer_fields"
|
|
down_revision = "0005_hotel_vehicle_modules"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
bind = op.get_bind()
|
|
if "HotelGroup" not in set(inspect(bind).get_table_names()):
|
|
return
|
|
|
|
columns = {column["name"] for column in inspect(bind).get_columns("HotelGroup")}
|
|
if "coverImage" not in columns:
|
|
op.add_column("HotelGroup", sa.Column("coverImage", sa.String(), nullable=True))
|
|
op.execute('UPDATE "HotelGroup" SET "coverImage" = image WHERE "coverImage" IS NULL')
|
|
if "priceAmount" not in columns:
|
|
op.add_column("HotelGroup", sa.Column("priceAmount", sa.Integer(), nullable=True))
|
|
if "priceUnit" not in columns:
|
|
op.add_column("HotelGroup", sa.Column("priceUnit", sa.String(), nullable=True, server_default="起/晚"))
|
|
if "tags" not in columns:
|
|
op.add_column(
|
|
"HotelGroup",
|
|
sa.Column(
|
|
"tags",
|
|
postgresql.ARRAY(sa.String()),
|
|
nullable=False,
|
|
server_default=sa.text("'{}'::varchar[]"),
|
|
),
|
|
)
|
|
if "status" not in columns:
|
|
op.add_column("HotelGroup", sa.Column("status", sa.String(), nullable=False, server_default="published"))
|
|
|
|
|
|
def downgrade() -> None:
|
|
bind = op.get_bind()
|
|
if "HotelGroup" not in set(inspect(bind).get_table_names()):
|
|
return
|
|
|
|
columns = {column["name"] for column in inspect(bind).get_columns("HotelGroup")}
|
|
for column_name in ["status", "tags", "priceUnit", "priceAmount", "coverImage"]:
|
|
if column_name in columns:
|
|
op.drop_column("HotelGroup", column_name) |