Free rooms first implementation
This commit is contained in:
@@ -18,6 +18,8 @@ from sqlalchemy import (
|
||||
Index,
|
||||
Integer,
|
||||
String,
|
||||
UniqueConstraint,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.exc import DBAPIError
|
||||
from sqlalchemy.ext.asyncio import (
|
||||
@@ -679,6 +681,66 @@ class ConversionRoom(Base):
|
||||
conversion = relationship("Conversion", back_populates="conversion_rooms")
|
||||
|
||||
|
||||
class HotelInventory(Base):
|
||||
"""Room and category definitions synchronized via AlpineBits."""
|
||||
|
||||
__tablename__ = "hotel_inventory"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
hotel_id = Column(
|
||||
String(50), ForeignKey("hotels.hotel_id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
inv_type_code = Column(String(8), nullable=False, index=True)
|
||||
inv_code = Column(String(16), nullable=True, index=True)
|
||||
room_name = Column(String(200), nullable=True)
|
||||
max_occupancy = Column(Integer, nullable=True)
|
||||
source = Column(String(20), nullable=False)
|
||||
first_seen = Column(DateTime(timezone=True), nullable=False)
|
||||
last_updated = Column(DateTime(timezone=True), nullable=False)
|
||||
|
||||
hotel = relationship("Hotel", back_populates="inventory_items")
|
||||
availability = relationship(
|
||||
"RoomAvailability",
|
||||
back_populates="inventory_item",
|
||||
cascade="all, delete-orphan",
|
||||
passive_deletes=True,
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"uq_hotel_inventory_unique_key",
|
||||
"hotel_id",
|
||||
"inv_type_code",
|
||||
func.coalesce(inv_code, ""),
|
||||
unique=True,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class RoomAvailability(Base):
|
||||
"""Daily availability counts for inventory items."""
|
||||
|
||||
__tablename__ = "room_availability"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
inventory_id = Column(
|
||||
Integer, ForeignKey("hotel_inventory.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
date = Column(Date, nullable=False, index=True)
|
||||
count_type_2 = Column(Integer, nullable=True)
|
||||
count_type_6 = Column(Integer, nullable=True)
|
||||
count_type_9 = Column(Integer, nullable=True)
|
||||
is_closing_season = Column(Boolean, nullable=False, default=False)
|
||||
last_updated = Column(DateTime(timezone=True), nullable=False)
|
||||
update_type = Column(String(20), nullable=False)
|
||||
|
||||
inventory_item = relationship("HotelInventory", back_populates="availability")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("inventory_id", "date", name="uq_room_availability_unique_key"),
|
||||
)
|
||||
|
||||
|
||||
class Hotel(Base):
|
||||
"""Hotel configuration (migrated from alpine_bits_auth in config.yaml)."""
|
||||
|
||||
@@ -710,6 +772,9 @@ class Hotel(Base):
|
||||
|
||||
# Relationships
|
||||
webhook_endpoints = relationship("WebhookEndpoint", back_populates="hotel")
|
||||
inventory_items = relationship(
|
||||
"HotelInventory", back_populates="hotel", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
|
||||
class WebhookEndpoint(Base):
|
||||
|
||||
Reference in New Issue
Block a user