TableGroup gains prefix and color columns for display in the PWA zone filter. Table creation now assigns a global auto-increment number; batch creation uses group-local label numbering (avoids gaps/conflicts when adding to existing groups). DELETE table now blocks if an active order exists (soft or hard delete). Hard delete cascades past orders before removing the table row. list_tables enriches each TableOut with has_active_order computed server-side. TableOut no longer requires number in the input payload; TableCreate simplified. Migration runner refactored to give each ALTER TABLE its own connection so a no-op (column already exists) doesn't leave a dirty transaction blocking later migrations. New migrations added for all new columns. Order.print_logs relationship gains cascade="all, delete-orphan" so print logs are removed when an order is deleted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from sqlalchemy import Column, Integer, String, Boolean, Float, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from database import Base
|
|
|
|
|
|
class TableGroup(Base):
|
|
__tablename__ = "table_groups"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, nullable=False, unique=True)
|
|
prefix = Column(String, nullable=True)
|
|
sort_order = Column(Integer, default=0)
|
|
color = Column(String, nullable=True)
|
|
|
|
tables = relationship("Table", back_populates="group")
|
|
|
|
|
|
class Table(Base):
|
|
__tablename__ = "tables"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
number = Column(Integer, nullable=False)
|
|
label = Column(String, nullable=True)
|
|
group_id = Column(Integer, ForeignKey("table_groups.id"), nullable=True)
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
|
floor_x = Column(Float, nullable=True)
|
|
floor_y = Column(Float, nullable=True)
|
|
|
|
group = relationship("TableGroup", back_populates="tables")
|
|
orders = relationship("Order", back_populates="table")
|