Files
WonderQ-Admin/alembic/versions/0006_hotel_group_offer_fields.py
duanshuwen 1aac3c64b2 feat(hotelGroups): add offer display fields and related logic
- Add new database columns (coverImage, priceAmount, priceUnit, tags, status) to HotelGroup model
- Create hotel_group_dict serializer to handle image/coverImage synchronization and tag formatting
- Update site config endpoints to use the new serializer and filter published hotel groups
- Add Alembic migration for the new database schema changes
- Update test fixtures and API contract tests for the new fields
- Revise public and admin API documentation to document the new hotel group fields and usage rules
2026-07-03 22:44:57 +08:00

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)