Files
aza/backup backup backup backup/backup 24.2.26 - Kopie/workforce_planner/seed.py
2026-03-30 07:59:11 +02:00

110 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""
Seed-Script: erstellt Datenbank-Tabellen und fügt Test-Mitarbeiter ein.
python -m workforce_planner.seed
"""
from .database import init_db, SessionLocal
from .core.models import Employee, Practice, BalanceAccount
from .core.enums import EmployeeRole
from .api.auth import hash_password
def seed():
print("Erstelle Tabellen ...")
init_db()
db = SessionLocal()
try:
if db.query(Practice).count() > 0:
print("Datenbank enthält bereits Daten überspringe Seed.")
return
praxis = Practice(
id="praxis_1",
name="Praxis Muster",
address="Musterstrasse 1, 8000 Zürich",
phone="+41 44 123 45 67",
)
db.add(praxis)
db.flush()
employees = [
Employee(
id="admin_1",
practice_id=praxis.id,
name="Dr. Admin",
email="admin@praxis.ch",
password_hash=hash_password("admin123"),
role=EmployeeRole.ADMIN,
vacation_days_per_year=25,
),
Employee(
id="manager_1",
practice_id=praxis.id,
name="Anna Meier",
email="anna@praxis.ch",
password_hash=hash_password("test123"),
role=EmployeeRole.MANAGER,
department="Leitung",
vacation_days_per_year=25,
),
Employee(
id="emp_1",
practice_id=praxis.id,
name="Stefan Müller",
email="stefan@praxis.ch",
password_hash=hash_password("test123"),
role=EmployeeRole.EMPLOYEE,
department="MPA",
vacation_days_per_year=25,
),
Employee(
id="emp_2",
practice_id=praxis.id,
name="Lisa Weber",
email="lisa@praxis.ch",
password_hash=hash_password("test123"),
role=EmployeeRole.EMPLOYEE,
department="MPA",
vacation_days_per_year=20,
),
Employee(
id="emp_3",
practice_id=praxis.id,
name="Marco Brunner",
email="marco@praxis.ch",
password_hash=hash_password("test123"),
role=EmployeeRole.EMPLOYEE,
department="Labor",
vacation_days_per_year=25,
),
]
for emp in employees:
db.add(emp)
db.flush()
import datetime
year = datetime.date.today().year
for emp in employees:
ba = BalanceAccount(
employee_id=emp.id,
year=year,
yearly_quota=emp.vacation_days_per_year,
)
db.add(ba)
db.commit()
print(f"Seed erfolgreich: 1 Praxis, {len(employees)} Mitarbeiter, Jahr {year}")
for emp in employees:
print(f" {emp.role.value:10s} {emp.name:20s} {emp.email} (Passwort: {'admin123' if emp.role == EmployeeRole.ADMIN else 'test123'})")
finally:
db.close()
if __name__ == "__main__":
seed()