Files
Salus/app/database.py
T
cgasserandClaude Sonnet 4.6 1ec63844ce Add M365 mapping/prices export-import, license pricing, and PDF summary export
- Mapping (Username/QWE Client/IsRestaurant): CSV export and import via new routes
- License prices: persistent DB table (M365LicensePrice), editable price card with auto-save, CSV export/import
- Summary table: Monthly Cost column per client + grand-total row, calculated live in JS from current prices
- PDF export: client-side jsPDF/autotable, landscape A4, includes cost column when prices are set

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-09 16:05:26 +02:00

54 lines
1.7 KiB
Python

import os
import datetime
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Boolean, Float
from sqlalchemy.orm import declarative_base, sessionmaker
DATABASE_URL = f"sqlite:///{os.getenv('DB_PATH', '/data/audit.db')}"
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
class M365UserOverride(Base):
__tablename__ = "m365_user_overrides"
username = Column(String, primary_key=True) # User principal name
qwe_client = Column(String, default="", nullable=False)
is_restaurant = Column(Boolean, default=False, nullable=False)
updated_at = Column(DateTime, default=datetime.datetime.utcnow)
class M365LicensePrice(Base):
__tablename__ = "m365_license_prices"
license_key = Column(String, primary_key=True)
price = Column(Float, default=0.0, nullable=False)
updated_at = Column(DateTime, default=datetime.datetime.utcnow)
class RebootLog(Base):
__tablename__ = "reboot_log"
id = Column(Integer, primary_key=True, index=True)
timestamp = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)
username = Column(String, nullable=False)
user_email = Column(String, nullable=False)
ap_name = Column(String, nullable=False)
ap_mac = Column(String, nullable=False)
ap_ip = Column(String, nullable=True)
result = Column(String, nullable=False) # "success" | "error"
error_message = Column(String, nullable=True)
def init_db():
Base.metadata.create_all(bind=engine)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()