feat(cloud): Alembic, license token v2 with modules, plan presets, module editor

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>
This commit is contained in:
2026-11-12 19:27:47 +02:00
co-authored by Claude Opus 5.5
parent 048b46af41
commit 48fd10df77
30 changed files with 1306 additions and 61 deletions
+7 -1
View File
@@ -34,6 +34,8 @@ TLS and domains are handled in front of these ports on the VPS (`xenia-api.bonam
## Pack-specific rules
> **Branch `platform-v2`:** CL-1 applies **within v2** only (v1 sites stay on the `main` cloud until cutover, D-21), and CL-2 is replaced by Alembic (below). The license token is `v: 2` with a `modules` map (CL-6).
**CL-1. Old sites are always talking to you.**
Sites upgrade slowly, and some may be several versions behind. Every endpoint a site calls (the contract, C-1 … C-7) must stay backward compatible:
- add optional fields only
@@ -42,7 +44,8 @@ Sites upgrade slowly, and some may be several versions behind. Every endpoint a
Any change to one of these endpoints updates the parent's `docs/reference/cloud-contract.md` (global Rule 6).
**CL-2. Schema changes go through `_run_migrations()`** in `cloud_backend/main.py`: additive `ALTER TABLE ... ADD COLUMN` only, and never drop columns. Superseded columns stay, with a comment (e.g. `menu_hours_en`).
**CL-2. Schema changes are Alembic revisions** (branch `platform-v2`, D-22). Change the model, add it to `models/all.py` if new, then from `cloud_backend/`: `alembic revision --autogenerate --rev-id NNNN_short_name -m "..."`, review the file, run `python -m pytest tests -q` (drift guard, stamp+upgrade test). `create_all` is never used. The production DB is stamped to `0001_cloud_baseline` once at cutover (`DEPLOYMENT_GUIDE.md` → Part 6); until then the v2 cloud refuses it.
*(On `main`, the v1 rule still applies: `_run_migrations()`, additive only.)*
**CL-3. The cloud is never on the service-critical path.**
If the cloud is down, restaurants must keep taking orders (global Rule 8). Don't design features where the local site blocks while waiting on the cloud.
@@ -56,6 +59,8 @@ If the cloud is down, restaurants must keep taking orders (global Rule 8). Don't
**CL-5. Frontend URLs are baked in at build time.**
`VITE_CLOUD_URL` is a build arg, so changing it means rebuilding the image, not restarting it.
**CL-7. Licensed modules live in `sites.modules`** (v2). The sysadmin panel edits them (per site, or by applying a plan preset from `/api/presets`). The module editor is built from the catalogue each site reports in its heartbeat (`sites.module_catalog`), with `sysadmin_panel/src/moduleCatalog.js` as the fallback; keep that file in step with the local manifests.
## Common commands
```bash
@@ -64,6 +69,7 @@ cd ~/stacks/xenia-pos-cloud && docker compose up -d --build
# Dev
cd cloud_backend && uvicorn main:app --reload --port 8001
cd cloud_backend && python -m pytest tests -q # schema guards, licensing v2 (pip install -r requirements-dev.txt)
cd sysadmin_panel && npm run dev
cd connect_frontend/menu-app && npm run dev
cd connect_frontend/manager-app && npm run dev