Files
xenia-pos-cloud/cloud_backend/models/site.py
bonamin 835806f92d feat(connect): Phase 2 — cloud DB models for Xenia Connect
Adds three new tables created automatically by create_all on next
startup, plus an additive migration for an existing table:

models/menu_snapshot.py (NEW)
  - menu_snapshots: one row per site, holds the full serialized
    category+product JSON; upserted on each sync from local_backend

models/online_order.py (NEW)
  - online_orders: full order lifecycle from customer submission
    through delivery; tracks sync state so local_backend can poll
    for unprocessed orders (synced_to_local=0)

models/manager_account.py (NEW)
  - manager_accounts + manager_site_access (M2M join table): remote
    manager login accounts with per-site access control

models/site.py (MODIFIED)
  - order_counter column added; incremented atomically when each
    online order is created to generate "ORD-XXXX" public_ref values

main.py (MODIFIED)
  - imports all three new models so create_all registers their tables
  - _run_migrations() added (same pattern as local_backend) for the
    additive order_counter column on the existing sites table

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 00:01:02 +03:00

26 lines
1.1 KiB
Python

from sqlalchemy import Column, Integer, String, Boolean, DateTime
from sqlalchemy.sql import func
from database import Base
class Site(Base):
__tablename__ = "sites"
id = Column(Integer, primary_key=True, index=True)
site_id = Column(String, unique=True, nullable=False, index=True)
name = Column(String, nullable=False)
owner_name = Column(String, nullable=False)
contact_email = Column(String, nullable=False)
secret_key_hash = Column(String, nullable=False)
is_active = Column(Boolean, default=True)
is_locked = Column(Boolean, default=False)
lock_reason = Column(String, nullable=True)
license_expires_at = Column(DateTime(timezone=True), nullable=False)
created_at = Column(DateTime(timezone=True), server_default=func.now())
last_seen_at = Column(DateTime(timezone=True), nullable=True)
last_seen_ip = Column(String, nullable=True)
last_seen_local_ip = Column(String, nullable=True)
waiter_domain = Column(String, nullable=True)
# Monotonically incrementing counter used to generate public_ref for online orders
order_counter = Column(Integer, default=0, nullable=False)