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>
119 lines
3.8 KiB
SQL
119 lines
3.8 KiB
SQL
-- The v1 production cloud schema (create_all + _run_migrations on main, 2026-11-12).
|
|
-- Frozen fixture for tests/test_schema.py: the v2 baseline must equal it, and a DB
|
|
-- in this shape must stamp + upgrade cleanly (APPS_PLATFORM D-22). Never edit.
|
|
|
|
CREATE TABLE admins (
|
|
id INTEGER NOT NULL,
|
|
username VARCHAR NOT NULL,
|
|
password_hash VARCHAR NOT NULL,
|
|
role VARCHAR,
|
|
PRIMARY KEY (id),
|
|
UNIQUE (username)
|
|
);
|
|
CREATE TABLE manager_accounts (
|
|
id INTEGER NOT NULL,
|
|
email VARCHAR NOT NULL,
|
|
password_hash VARCHAR NOT NULL,
|
|
full_name VARCHAR,
|
|
is_active INTEGER NOT NULL,
|
|
created_at DATETIME DEFAULT (CURRENT_TIMESTAMP),
|
|
PRIMARY KEY (id)
|
|
);
|
|
CREATE TABLE manager_site_access (
|
|
manager_id INTEGER NOT NULL,
|
|
site_id INTEGER NOT NULL,
|
|
PRIMARY KEY (manager_id, site_id),
|
|
FOREIGN KEY(manager_id) REFERENCES manager_accounts (id),
|
|
FOREIGN KEY(site_id) REFERENCES sites (id)
|
|
);
|
|
CREATE TABLE menu_snapshots (
|
|
id INTEGER NOT NULL,
|
|
site_id INTEGER NOT NULL,
|
|
snapshot_json TEXT NOT NULL,
|
|
updated_at DATETIME DEFAULT (CURRENT_TIMESTAMP),
|
|
PRIMARY KEY (id),
|
|
FOREIGN KEY(site_id) REFERENCES sites (id)
|
|
);
|
|
CREATE TABLE online_orders (
|
|
id INTEGER NOT NULL,
|
|
site_id INTEGER NOT NULL,
|
|
public_ref VARCHAR NOT NULL,
|
|
order_type VARCHAR NOT NULL,
|
|
customer_name VARCHAR NOT NULL,
|
|
customer_phone VARCHAR,
|
|
customer_address TEXT,
|
|
customer_notes TEXT,
|
|
items_json TEXT NOT NULL,
|
|
subtotal FLOAT NOT NULL,
|
|
delivery_fee FLOAT NOT NULL,
|
|
total FLOAT NOT NULL,
|
|
status VARCHAR NOT NULL,
|
|
rejection_reason VARCHAR,
|
|
synced_to_local INTEGER NOT NULL,
|
|
local_order_id INTEGER,
|
|
created_at DATETIME DEFAULT (CURRENT_TIMESTAMP),
|
|
updated_at DATETIME DEFAULT (CURRENT_TIMESTAMP),
|
|
PRIMARY KEY (id),
|
|
FOREIGN KEY(site_id) REFERENCES sites (id),
|
|
UNIQUE (public_ref)
|
|
);
|
|
CREATE TABLE product_images (
|
|
id INTEGER NOT NULL,
|
|
site_id INTEGER NOT NULL,
|
|
product_id INTEGER NOT NULL,
|
|
image_url VARCHAR NOT NULL,
|
|
image_hash VARCHAR NOT NULL,
|
|
updated_at DATETIME DEFAULT (CURRENT_TIMESTAMP),
|
|
PRIMARY KEY (id),
|
|
CONSTRAINT uq_product_images_site_product UNIQUE (site_id, product_id),
|
|
FOREIGN KEY(site_id) REFERENCES sites (id)
|
|
);
|
|
CREATE TABLE sites (
|
|
id INTEGER NOT NULL,
|
|
site_id VARCHAR NOT NULL,
|
|
name VARCHAR NOT NULL,
|
|
owner_name VARCHAR NOT NULL,
|
|
contact_email VARCHAR NOT NULL,
|
|
secret_key_hash VARCHAR NOT NULL,
|
|
is_active BOOLEAN,
|
|
is_locked BOOLEAN,
|
|
lock_reason VARCHAR,
|
|
license_expires_at DATETIME NOT NULL,
|
|
created_at DATETIME DEFAULT (CURRENT_TIMESTAMP),
|
|
last_seen_at DATETIME,
|
|
last_seen_ip VARCHAR,
|
|
last_seen_local_ip VARCHAR,
|
|
waiter_domain VARCHAR,
|
|
order_counter INTEGER NOT NULL,
|
|
menu_mode VARCHAR NOT NULL,
|
|
menu_display_name VARCHAR,
|
|
menu_tagline_en VARCHAR,
|
|
menu_tagline_gr VARCHAR,
|
|
menu_blurb_en VARCHAR,
|
|
menu_blurb_gr VARCHAR,
|
|
menu_hours VARCHAR,
|
|
menu_header_image_url VARCHAR, menu_hours_en VARCHAR, menu_hours_gr VARCHAR,
|
|
PRIMARY KEY (id)
|
|
);
|
|
CREATE TABLE stats_snapshots (
|
|
id INTEGER NOT NULL,
|
|
site_id INTEGER NOT NULL,
|
|
snapshot_json TEXT NOT NULL,
|
|
updated_at DATETIME DEFAULT (CURRENT_TIMESTAMP),
|
|
PRIMARY KEY (id),
|
|
UNIQUE (site_id),
|
|
FOREIGN KEY(site_id) REFERENCES sites (id)
|
|
);
|
|
CREATE INDEX ix_admins_id ON admins (id);
|
|
CREATE UNIQUE INDEX ix_manager_accounts_email ON manager_accounts (email);
|
|
CREATE INDEX ix_manager_accounts_id ON manager_accounts (id);
|
|
CREATE INDEX ix_menu_snapshots_id ON menu_snapshots (id);
|
|
CREATE UNIQUE INDEX ix_menu_snapshots_site_id ON menu_snapshots (site_id);
|
|
CREATE INDEX ix_online_orders_id ON online_orders (id);
|
|
CREATE INDEX ix_online_orders_site_id ON online_orders (site_id);
|
|
CREATE INDEX ix_online_orders_status ON online_orders (status);
|
|
CREATE INDEX ix_product_images_id ON product_images (id);
|
|
CREATE INDEX ix_product_images_site_id ON product_images (site_id);
|
|
CREATE INDEX ix_sites_id ON sites (id);
|
|
CREATE UNIQUE INDEX ix_sites_site_id ON sites (site_id);
|