Initial KDS scaffold — Phase 2 kitchen port
FastAPI backend (Python 3.11, httpx for SignalR/GraphQL — no MSSQL ODBC), shares kitchen_db directly. React/TS/Vite fullscreen board frontend. Backend: auth.py (APP_SLUG=kds, SimpleNamespace), main.py (4 KDS migrations, SignalR start/stop), kds.py router, models (kds/settings/resos — read from kitchen_db), signalr_listener.py (backoff pre-existing), kds_graphql.py, database.py. Requirements stripped to ~9 packages; image ~400 MB lighter than kitchen (no MSSQL ODBC layer). Frontend: AuthGate (app=kds), single fullscreen route, dark board theme. KDS.tsx URL prefix patched (/api/kds/ → /kds/api/kds/), recipe images cross-app (/kitchen/api/recipes/). nginx: 5 blocks with SSE proxy headers on /kds/api/ block. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
b94585084a
35 changed files with 5195 additions and 0 deletions
0
backend/migrations/__init__.py
Normal file
0
backend/migrations/__init__.py
Normal file
38
backend/migrations/add_kds_bookings_refresh.py
Normal file
38
backend/migrations/add_kds_bookings_refresh.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""
|
||||
Migration: Add KDS bookings refresh interval setting.
|
||||
|
||||
Adds:
|
||||
- kds_bookings_refresh_seconds column to kitchen_settings
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from sqlalchemy import text
|
||||
from database import engine
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def run_migration():
|
||||
"""Add KDS bookings refresh interval column."""
|
||||
|
||||
alter_statements = [
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_bookings_refresh_seconds INTEGER DEFAULT 60
|
||||
""",
|
||||
]
|
||||
|
||||
try:
|
||||
async with engine.begin() as conn:
|
||||
for sql in alter_statements:
|
||||
await conn.execute(text(sql))
|
||||
logger.info("Added KDS bookings refresh interval column")
|
||||
except Exception as e:
|
||||
if "already exists" not in str(e).lower():
|
||||
raise
|
||||
logger.warning(f"KDS bookings refresh migration: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(run_migration())
|
||||
54
backend/migrations/add_kds_course_flow.py
Normal file
54
backend/migrations/add_kds_course_flow.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
"""
|
||||
Migration: Add KDS course flow settings (away timer thresholds)
|
||||
and action column to course bumps audit trail.
|
||||
|
||||
Adds:
|
||||
- kds_away_timer_green/amber/red_seconds to kitchen_settings
|
||||
- action column to kds_course_bumps
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from sqlalchemy import text
|
||||
from database import engine
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def run_migration():
|
||||
"""Add KDS course flow columns."""
|
||||
|
||||
alter_statements = [
|
||||
# Away timer thresholds (time since food sent to table)
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_away_timer_green_seconds INTEGER DEFAULT 600
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_away_timer_amber_seconds INTEGER DEFAULT 900
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_away_timer_red_seconds INTEGER DEFAULT 1200
|
||||
""",
|
||||
# Action column on course bumps audit trail ('away' or 'sent')
|
||||
"""
|
||||
ALTER TABLE kds_course_bumps
|
||||
ADD COLUMN IF NOT EXISTS action VARCHAR(20) DEFAULT 'sent'
|
||||
""",
|
||||
]
|
||||
|
||||
try:
|
||||
async with engine.begin() as conn:
|
||||
for sql in alter_statements:
|
||||
await conn.execute(text(sql))
|
||||
logger.info("Added KDS course flow columns")
|
||||
except Exception as e:
|
||||
if "already exists" not in str(e).lower():
|
||||
raise
|
||||
logger.warning(f"KDS course flow migration: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(run_migration())
|
||||
39
backend/migrations/add_kds_order_tracking.py
Normal file
39
backend/migrations/add_kds_order_tracking.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"""
|
||||
Migration: Add KDS per-order tracking column.
|
||||
|
||||
Adds:
|
||||
- initial_order_ids JSONB column to kds_tickets (captures order IDs at ticket creation
|
||||
for detecting +ADDITION orders added later)
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from sqlalchemy import text
|
||||
from database import engine
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def run_migration():
|
||||
"""Add KDS order tracking column."""
|
||||
|
||||
alter_statements = [
|
||||
"""
|
||||
ALTER TABLE kds_tickets
|
||||
ADD COLUMN IF NOT EXISTS initial_order_ids JSONB
|
||||
""",
|
||||
]
|
||||
|
||||
try:
|
||||
async with engine.begin() as conn:
|
||||
for sql in alter_statements:
|
||||
await conn.execute(text(sql))
|
||||
logger.info("Added KDS order tracking column (initial_order_ids)")
|
||||
except Exception as e:
|
||||
if "already exists" not in str(e).lower():
|
||||
raise
|
||||
logger.warning(f"KDS order tracking migration: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(run_migration())
|
||||
124
backend/migrations/add_kds_tables.py
Normal file
124
backend/migrations/add_kds_tables.py
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
"""
|
||||
Migration: Add KDS (Kitchen Display System) tables and settings
|
||||
|
||||
Creates:
|
||||
- kds_tickets: Local ticket state tracking
|
||||
- kds_course_bumps: Course bump audit trail
|
||||
- KDS settings columns in kitchen_settings
|
||||
"""
|
||||
|
||||
import logging
|
||||
from sqlalchemy import text
|
||||
from database import engine
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def run_migration():
|
||||
"""Add KDS tables and settings columns."""
|
||||
migrations = [
|
||||
# KDS settings columns in kitchen_settings
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_enabled BOOLEAN DEFAULT FALSE
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_graphql_url VARCHAR(500)
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_graphql_username VARCHAR(255)
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_graphql_password VARCHAR(500)
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_graphql_client_id VARCHAR(255)
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_poll_interval_seconds INTEGER DEFAULT 6000
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_timer_green_seconds INTEGER DEFAULT 300
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_timer_amber_seconds INTEGER DEFAULT 600
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_timer_red_seconds INTEGER DEFAULT 900
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_course_order JSONB DEFAULT '["Starters", "Mains", "Desserts"]'::jsonb
|
||||
""",
|
||||
"""
|
||||
ALTER TABLE kitchen_settings
|
||||
ADD COLUMN IF NOT EXISTS kds_show_completed_for_seconds INTEGER DEFAULT 30
|
||||
""",
|
||||
|
||||
# KDS Tickets table
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS kds_tickets (
|
||||
id SERIAL PRIMARY KEY,
|
||||
kitchen_id INTEGER NOT NULL REFERENCES kitchens(id),
|
||||
sambapos_ticket_id INTEGER NOT NULL,
|
||||
sambapos_ticket_uid VARCHAR(100),
|
||||
ticket_number VARCHAR(50) NOT NULL,
|
||||
table_name VARCHAR(100),
|
||||
covers INTEGER,
|
||||
total_amount FLOAT,
|
||||
received_at TIMESTAMP DEFAULT NOW(),
|
||||
last_sambapos_update TIMESTAMP,
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
is_bumped BOOLEAN DEFAULT FALSE,
|
||||
bumped_at TIMESTAMP,
|
||||
course_states JSONB DEFAULT '{}'::jsonb,
|
||||
orders_data JSONB,
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW()
|
||||
)
|
||||
""",
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_kds_tickets_kitchen_id ON kds_tickets(kitchen_id)
|
||||
""",
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_kds_tickets_sambapos_id ON kds_tickets(sambapos_ticket_id)
|
||||
""",
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_kds_tickets_active ON kds_tickets(kitchen_id, is_active)
|
||||
""",
|
||||
|
||||
# KDS Course Bumps table
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS kds_course_bumps (
|
||||
id SERIAL PRIMARY KEY,
|
||||
ticket_id INTEGER NOT NULL REFERENCES kds_tickets(id) ON DELETE CASCADE,
|
||||
course_name VARCHAR(100) NOT NULL,
|
||||
bumped_at TIMESTAMP DEFAULT NOW(),
|
||||
bumped_by_user_id INTEGER REFERENCES users(id),
|
||||
time_since_previous_seconds INTEGER
|
||||
)
|
||||
""",
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_kds_course_bumps_ticket_id ON kds_course_bumps(ticket_id)
|
||||
""",
|
||||
]
|
||||
|
||||
for sql in migrations:
|
||||
try:
|
||||
async with engine.begin() as conn:
|
||||
await conn.execute(text(sql.strip()))
|
||||
logger.info(f"KDS Migration executed: {sql.strip()[:60]}...")
|
||||
except Exception as e:
|
||||
error_str = str(e).lower()
|
||||
if "already exists" in error_str or "duplicate" in error_str:
|
||||
logger.info(f"KDS Migration: already exists, skipping")
|
||||
else:
|
||||
logger.warning(f"KDS Migration warning: {e}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue