Unzip budget-app v7 into repo root

This commit is contained in:
jpmvaz
2026-10-29 20:40:02 +00:00
parent 2554e68315
commit c9fd26f1c7
94 changed files with 12098 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
"""Run once at container start: creates the first admin and the default categories and sites."""
from sqlalchemy import func, select
from .config import settings
from .db import SessionLocal
from .models import Category, Department, Site, User
from .security import hash_password
from .seed import CATEGORIES, SITES
DEFAULT_DEPARTMENT = "IT"
def seed_categories(db, department: Department) -> None:
for i, (en, pt, section) in enumerate(CATEGORIES):
db.add(Category(department_id=department.id, name_en=en, name_pt=pt, section=section, sort_order=(i + 1) * 10))
def bootstrap() -> None:
with SessionLocal() as db:
if not db.scalar(select(func.count(Department.id))):
dept = Department(name=DEFAULT_DEPARTMENT)
db.add(dept)
db.flush()
seed_categories(db, dept)
if not db.scalar(select(func.count(User.id))):
db.add(User(email=settings.admin_email.lower(), name=settings.admin_name,
password_hash=hash_password(settings.admin_password), role="admin",
language=settings.default_language,
department_id=db.scalar(select(Department.id).order_by(Department.id))))
print(f"Created admin user {settings.admin_email}")
if not db.scalar(select(func.count(Site.id))):
for name in SITES:
db.add(Site(name=name))
db.commit()
if __name__ == "__main__":
bootstrap()