Platform v2 step 1.7 (APPS_PLATFORM D-3, D-20, D-21, D-22, §5.2).
- Alembic replaces create_all + _run_migrations. 0001_cloud_baseline is
exactly the v1 production schema (incl. the dead menu_hours_en/_gr), checked
against a frozen fixture; schema.py refuses an unstamped v1 DB, so prod is
stamped once at cutover (DEPLOYMENT_GUIDE Part 6)
- 0002_v2_licensing: sites.modules (JSON), sites.module_catalog(_at),
plan_presets; existing sites get every module v1 had (KDS unlimited); the
same map is seeded as preset "Everything (v1 sites)"; dead columns dropped
- license token v: 2 with a normalized `modules` map
- heartbeat v2: request {version, local_ip, module_catalog} (catalogue stored
per site); response {license_token, latest_version, waiter_domain,
site_numeric_id} - the unsigned v1 license fields are gone
- sites API: create with a preset, PUT /{id}/modules (validated),
POST /{id}/apply-preset/{preset}; /api/presets CRUD
- sysadmin panel: Licensed modules card per site (built from the reported
catalogue, fallback list), preset picker on register, Presets page
- .dockerignore: local *.db, .env and tests no longer baked into the image
- tests (new): baseline = v1, unstamped refused, stamp+upgrade of a v1 DB,
drift, token v2 shape/signature, module edits, presets; CL-2/CL-7 rules
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
2.6 KiB
Python
71 lines
2.6 KiB
Python
"""Cloud backend entry point. Schema: Alembic only (schema.py, APPS_PLATFORM D-22)."""
|
|
import os
|
|
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from config import settings
|
|
from database import engine
|
|
from auth_utils import hash_password
|
|
import models.all # noqa: F401 every model (Alembic + routers)
|
|
|
|
from routers import auth, sites, heartbeat, presets
|
|
from routers import menu as menu_router
|
|
from routers import orders as orders_router
|
|
from routers import manager_auth as manager_auth_router
|
|
from routers import remote_dashboard as remote_dashboard_router
|
|
|
|
|
|
def _seed_default_admin():
|
|
from sqlalchemy.orm import Session
|
|
from models.admin import Admin
|
|
|
|
with Session(engine) as db:
|
|
if not db.query(Admin).filter(Admin.username == settings.ADMIN_USERNAME).first():
|
|
db.add(Admin(
|
|
username=settings.ADMIN_USERNAME,
|
|
password_hash=hash_password(settings.ADMIN_PASSWORD),
|
|
role="sysadmin",
|
|
))
|
|
db.commit()
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Schema = Alembic revisions only (schema.py, D-22). Refuses an unstamped v1 database.
|
|
from schema import upgrade_to_head
|
|
upgrade_to_head()
|
|
_seed_default_admin()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="POS Cloud Backend", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
|
|
app.include_router(sites.router, prefix="/api/sites", tags=["sites"])
|
|
app.include_router(heartbeat.router, prefix="/api/heartbeat", tags=["heartbeat"])
|
|
app.include_router(presets.router, prefix="/api/presets", tags=["presets"])
|
|
app.include_router(menu_router.router, prefix="/api/menu", tags=["menu"])
|
|
app.include_router(orders_router.router, prefix="/api/orders", tags=["orders"])
|
|
app.include_router(manager_auth_router.router, prefix="/api/manager", tags=["manager"])
|
|
app.include_router(remote_dashboard_router.router,prefix="/api/remote", tags=["remote"])
|
|
|
|
os.makedirs("/app/data/site_headers", exist_ok=True)
|
|
app.mount("/static/site_headers", StaticFiles(directory="/app/data/site_headers"), name="site_headers")
|
|
|
|
os.makedirs("/app/data/product_images", exist_ok=True)
|
|
app.mount("/static/product_images", StaticFiles(directory="/app/data/product_images"), name="product_images")
|
|
|
|
|
|
@app.get("/health")
|
|
def health():
|
|
return {"status": "ok"}
|