feat: initial implementation
This commit is contained in:
commit
e29da874ee
39 files changed
+2309
No files matched your search
@@ -0,0 +1,60 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .config import settings
|
||||
from .models import Schedule, User
|
||||
from .security import hash_password
|
||||
|
||||
|
||||
def ensure_initial_data(db: Session) -> None:
|
||||
user_count = db.scalar(select(User.id).limit(1))
|
||||
if user_count is None:
|
||||
db.add(
|
||||
User(
|
||||
name=settings.initial_admin_name,
|
||||
username=settings.initial_admin_username,
|
||||
email=settings.initial_admin_email or None,
|
||||
phone=None,
|
||||
password_hash=hash_password(settings.initial_admin_password),
|
||||
is_admin=True,
|
||||
is_active=True,
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
defaults = [
|
||||
{
|
||||
"name": "Night",
|
||||
"slug": "night",
|
||||
"schedule_type": "fixed",
|
||||
"weekdays": "0,1,2,3,4,5,6",
|
||||
"label_time": "Night",
|
||||
"rotation_anchor_date": None,
|
||||
},
|
||||
{
|
||||
"name": "Saturday Lunch",
|
||||
"slug": "saturday-lunch",
|
||||
"schedule_type": "rotation",
|
||||
"weekdays": "5",
|
||||
"label_time": "Lunch",
|
||||
"rotation_anchor_date": date(2024, 1, 6),
|
||||
},
|
||||
{
|
||||
"name": "Sunday Lunch",
|
||||
"slug": "sunday-lunch",
|
||||
"schedule_type": "rotation",
|
||||
"weekdays": "6",
|
||||
"label_time": "Lunch",
|
||||
"rotation_anchor_date": date(2024, 1, 7),
|
||||
},
|
||||
]
|
||||
|
||||
for item in defaults:
|
||||
exists = db.scalar(select(Schedule.id).where(Schedule.slug == item["slug"]))
|
||||
if exists is None:
|
||||
db.add(Schedule(**item, requires_manager_approval=True, is_active=True))
|
||||
db.commit()
|
||||
Reference in new issue
Block a user