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>
192 lines
9.5 KiB
Python
192 lines
9.5 KiB
Python
"""cloud v1 baseline: exactly the schema the v1 production cloud has (D-22)
|
|
|
|
Autogenerated from the models, then hand-edited so it equals what v1's create_all +
|
|
_run_migrations() produce: sites also has menu_hours_en / menu_hours_gr (v1 superseded
|
|
them by menu_hours but never dropped them; 0002 drops them).
|
|
The production DB is never upgraded THROUGH this revision: it is stamped to it at
|
|
cutover, so this file must describe production, not an ideal schema.
|
|
tests/test_schema.py compares it with a database built by v1's code.
|
|
|
|
Revision ID: 0001_cloud_baseline
|
|
Revises:
|
|
Create Date: 2026-11-12 19:18:38.281895
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision = '0001_cloud_baseline'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table('admins',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('username', sa.String(), nullable=False),
|
|
sa.Column('password_hash', sa.String(), nullable=False),
|
|
sa.Column('role', sa.String(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('username')
|
|
)
|
|
with op.batch_alter_table('admins', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_admins_id'), ['id'], unique=False)
|
|
|
|
op.create_table('manager_accounts',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('password_hash', sa.String(), nullable=False),
|
|
sa.Column('full_name', sa.String(), nullable=True),
|
|
sa.Column('is_active', sa.Integer(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('manager_accounts', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_manager_accounts_email'), ['email'], unique=True)
|
|
batch_op.create_index(batch_op.f('ix_manager_accounts_id'), ['id'], unique=False)
|
|
|
|
op.create_table('sites',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('site_id', sa.String(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('owner_name', sa.String(), nullable=False),
|
|
sa.Column('contact_email', sa.String(), nullable=False),
|
|
sa.Column('secret_key_hash', sa.String(), nullable=False),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True),
|
|
sa.Column('is_locked', sa.Boolean(), nullable=True),
|
|
sa.Column('lock_reason', sa.String(), nullable=True),
|
|
sa.Column('license_expires_at', sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.Column('last_seen_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column('last_seen_ip', sa.String(), nullable=True),
|
|
sa.Column('last_seen_local_ip', sa.String(), nullable=True),
|
|
sa.Column('waiter_domain', sa.String(), nullable=True),
|
|
sa.Column('order_counter', sa.Integer(), nullable=False),
|
|
sa.Column('menu_mode', sa.String(), nullable=False),
|
|
sa.Column('menu_display_name', sa.String(), nullable=True),
|
|
sa.Column('menu_tagline_en', sa.String(), nullable=True),
|
|
sa.Column('menu_tagline_gr', sa.String(), nullable=True),
|
|
sa.Column('menu_blurb_en', sa.String(), nullable=True),
|
|
sa.Column('menu_blurb_gr', sa.String(), nullable=True),
|
|
sa.Column('menu_hours', sa.String(), nullable=True),
|
|
sa.Column('menu_hours_en', sa.String(), nullable=True),
|
|
sa.Column('menu_hours_gr', sa.String(), nullable=True),
|
|
sa.Column('menu_header_image_url', sa.String(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('sites', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_sites_id'), ['id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_sites_site_id'), ['site_id'], unique=True)
|
|
|
|
op.create_table('manager_site_access',
|
|
sa.Column('manager_id', sa.Integer(), nullable=False),
|
|
sa.Column('site_id', sa.Integer(), nullable=False),
|
|
sa.ForeignKeyConstraint(['manager_id'], ['manager_accounts.id'], ),
|
|
sa.ForeignKeyConstraint(['site_id'], ['sites.id'], ),
|
|
sa.PrimaryKeyConstraint('manager_id', 'site_id')
|
|
)
|
|
op.create_table('menu_snapshots',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('site_id', sa.Integer(), nullable=False),
|
|
sa.Column('snapshot_json', sa.Text(), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.ForeignKeyConstraint(['site_id'], ['sites.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('menu_snapshots', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_menu_snapshots_id'), ['id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_menu_snapshots_site_id'), ['site_id'], unique=True)
|
|
|
|
op.create_table('online_orders',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('site_id', sa.Integer(), nullable=False),
|
|
sa.Column('public_ref', sa.String(), nullable=False),
|
|
sa.Column('order_type', sa.String(), nullable=False),
|
|
sa.Column('customer_name', sa.String(), nullable=False),
|
|
sa.Column('customer_phone', sa.String(), nullable=True),
|
|
sa.Column('customer_address', sa.Text(), nullable=True),
|
|
sa.Column('customer_notes', sa.Text(), nullable=True),
|
|
sa.Column('items_json', sa.Text(), nullable=False),
|
|
sa.Column('subtotal', sa.Float(), nullable=False),
|
|
sa.Column('delivery_fee', sa.Float(), nullable=False),
|
|
sa.Column('total', sa.Float(), nullable=False),
|
|
sa.Column('status', sa.String(), nullable=False),
|
|
sa.Column('rejection_reason', sa.String(), nullable=True),
|
|
sa.Column('synced_to_local', sa.Integer(), nullable=False),
|
|
sa.Column('local_order_id', sa.Integer(), nullable=True),
|
|
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.ForeignKeyConstraint(['site_id'], ['sites.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('public_ref')
|
|
)
|
|
with op.batch_alter_table('online_orders', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_online_orders_id'), ['id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_online_orders_site_id'), ['site_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_online_orders_status'), ['status'], unique=False)
|
|
|
|
op.create_table('product_images',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('site_id', sa.Integer(), nullable=False),
|
|
sa.Column('product_id', sa.Integer(), nullable=False),
|
|
sa.Column('image_url', sa.String(), nullable=False),
|
|
sa.Column('image_hash', sa.String(), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.ForeignKeyConstraint(['site_id'], ['sites.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('site_id', 'product_id', name='uq_product_images_site_product')
|
|
)
|
|
with op.batch_alter_table('product_images', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_product_images_id'), ['id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_product_images_site_id'), ['site_id'], unique=False)
|
|
|
|
op.create_table('stats_snapshots',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('site_id', sa.Integer(), nullable=False),
|
|
sa.Column('snapshot_json', sa.Text(), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
|
|
sa.ForeignKeyConstraint(['site_id'], ['sites.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('site_id')
|
|
)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_table('stats_snapshots')
|
|
with op.batch_alter_table('product_images', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_product_images_site_id'))
|
|
batch_op.drop_index(batch_op.f('ix_product_images_id'))
|
|
|
|
op.drop_table('product_images')
|
|
with op.batch_alter_table('online_orders', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_online_orders_status'))
|
|
batch_op.drop_index(batch_op.f('ix_online_orders_site_id'))
|
|
batch_op.drop_index(batch_op.f('ix_online_orders_id'))
|
|
|
|
op.drop_table('online_orders')
|
|
with op.batch_alter_table('menu_snapshots', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_menu_snapshots_site_id'))
|
|
batch_op.drop_index(batch_op.f('ix_menu_snapshots_id'))
|
|
|
|
op.drop_table('menu_snapshots')
|
|
op.drop_table('manager_site_access')
|
|
with op.batch_alter_table('sites', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_sites_site_id'))
|
|
batch_op.drop_index(batch_op.f('ix_sites_id'))
|
|
|
|
op.drop_table('sites')
|
|
with op.batch_alter_table('manager_accounts', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_manager_accounts_id'))
|
|
batch_op.drop_index(batch_op.f('ix_manager_accounts_email'))
|
|
|
|
op.drop_table('manager_accounts')
|
|
with op.batch_alter_table('admins', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_admins_id'))
|
|
|
|
op.drop_table('admins')
|
|
# ### end Alembic commands ###
|