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,70 @@
|
||||
"""v2 licensing: site modules, catalogue, plan presets (D-3, D-20, D-21, §5.2)
|
||||
|
||||
Hand-edited:
|
||||
- existing sites get V1_SITE_MODULES: every module a v1 site already had, with no
|
||||
limits tighter than v1 (KDS screens unlimited). At cutover each site keeps doing what
|
||||
it did; the owner can then change sites in the sysadmin panel. Frozen here on purpose.
|
||||
- the same map is seeded as the preset "Everything (v1 sites)".
|
||||
- menu_hours_en / menu_hours_gr (superseded in v1) are dropped.
|
||||
|
||||
Revision ID: 0002_v2_licensing
|
||||
Revises: 0001_cloud_baseline
|
||||
Create Date: 2026-11-12 19:19:08.073899
|
||||
"""
|
||||
import json
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
V1_SITE_MODULES = {
|
||||
"ordering": {}, "waiter_app": {}, "history": {}, "reports": {}, "pricing": {}, "tabs": {},
|
||||
"crm": {}, "expenses": {}, "inventory": {}, "staff_planning": {}, "notes": {}, "chat": {},
|
||||
"reservations": {}, "kds": {"limits": {"devices": None}}, "connect_menu": {},
|
||||
"connect_orders": {}, "connect_remote": {}, "caller_id": {}, "fiscal": {},
|
||||
}
|
||||
|
||||
|
||||
revision = '0002_v2_licensing'
|
||||
down_revision = '0001_cloud_baseline'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('plan_presets',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.Column('description', sa.String(), nullable=True),
|
||||
sa.Column('modules', sa.JSON(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('name')
|
||||
)
|
||||
with op.batch_alter_table('sites', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('modules', sa.JSON(), nullable=False, server_default=sa.text("'{}'")))
|
||||
batch_op.add_column(sa.Column('module_catalog', sa.JSON(), nullable=True))
|
||||
batch_op.add_column(sa.Column('module_catalog_at', sa.DateTime(timezone=True), nullable=True))
|
||||
batch_op.drop_column('menu_hours_en')
|
||||
batch_op.drop_column('menu_hours_gr')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
conn = op.get_bind()
|
||||
conn.execute(sa.text("update sites set modules = :m"), {"m": json.dumps(V1_SITE_MODULES)})
|
||||
conn.execute(sa.text("insert into plan_presets (name, description, modules) values (:n, :d, :m)"),
|
||||
{"n": "Everything (v1 sites)", "d": "Every module v1 sites had, no extra limits",
|
||||
"m": json.dumps(V1_SITE_MODULES)})
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('sites', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('menu_hours_gr', sa.VARCHAR(), nullable=True))
|
||||
batch_op.add_column(sa.Column('menu_hours_en', sa.VARCHAR(), nullable=True))
|
||||
batch_op.drop_column('module_catalog_at')
|
||||
batch_op.drop_column('module_catalog')
|
||||
batch_op.drop_column('modules')
|
||||
|
||||
op.drop_table('plan_presets')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user