Files
xenia-pos-local/local_backend/seed.py
T
bonaminandClaude Opus 5.5 d3d328804e refactor(backend): Alembic owns the local schema; v1 ALTER list deleted
Platform v2 step 1.0 (APPS_PLATFORM D-13, D-17).
- migrations/ with env.py (render_as_batch, models/all.py metadata, no
  fileConfig) and baseline 0001_v2_baseline autogenerated from the models and
  reviewed; it also seeds the pos_settings rows a fresh v1 install got
- core/schema.py::upgrade_to_head() is the only way the schema is built:
  app startup, seed.py, demo_seed.py, wipe_database.py and the tests. It
  refuses v1 databases (tables without alembic_version) with a clear error
- main.py: _run_migrations() and create_all removed (723 lines)
- sync_events became a model (was raw DDL); price_event_log order indexes
  declared on the model; unused order_discounts.price_before/after dropped
- tests/guards: no-drift + idempotent upgrade + install defaults + v1 refusal
  + no create_all; placeholders for the time (1.1) and access (1.5) guards
- CS-1 rewritten for Alembic on this branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:54:15 +02:00

43 lines
1.6 KiB
Python

"""
Run once to bootstrap the database with initial data.
Usage: python seed.py
"""
import bcrypt
from database import SessionLocal
import models.all # noqa: F401
from core.schema import upgrade_to_head
upgrade_to_head()
db = SessionLocal()
try:
from models.user import User
from models.printer import Printer
# ── Manager account ───────────────────────────────────────────────────────
if not db.query(User).filter(User.username == "manager").first():
db.add(User(
username="manager",
pin_hash=bcrypt.hashpw(b"1234", bcrypt.gensalt()).decode(),
role="manager",
))
print("Created manager account (PIN: 1234)")
else:
print("Manager account already exists — skipping")
# ── Printers ──────────────────────────────────────────────────────────────
if not db.query(Printer).filter(Printer.name == "Kitchen").first():
db.add(Printer(name="Kitchen", ip_address="10.98.20.25", port=9100))
print("Created Kitchen printer")
if not db.query(Printer).filter(Printer.name == "Bar").first():
db.add(Printer(name="Bar", ip_address="10.98.20.25", port=9100))
print("Created Bar printer (update IP when you have a second printer)")
db.commit()
print("\nDone. Change the manager PIN after first login.")
finally:
db.close()