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:
@@ -0,0 +1,42 @@
|
||||
"""Alembic environment for cloud_backend (APPS_PLATFORM D-22).
|
||||
|
||||
Agent notes: target metadata = models/all.py; render_as_batch for SQLite; a caller may
|
||||
pass a connection in config.attributes["connection"] (schema.py, tests); otherwise
|
||||
config.settings.DATABASE_URL is used.
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from database import Base # noqa: E402
|
||||
import models.all # noqa: E402,F401
|
||||
|
||||
target_metadata = Base.metadata
|
||||
|
||||
|
||||
def _run(connection):
|
||||
context.configure(connection=connection, target_metadata=target_metadata,
|
||||
render_as_batch=True, compare_type=True)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
connection = context.config.attributes.get("connection")
|
||||
if connection is not None:
|
||||
_run(connection)
|
||||
return
|
||||
from config import settings
|
||||
engine = create_engine(settings.DATABASE_URL)
|
||||
with engine.connect() as conn:
|
||||
_run(conn)
|
||||
engine.dispose()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
raise SystemExit("Offline (--sql) mode is not supported.")
|
||||
run_migrations_online()
|
||||
Reference in New Issue
Block a user