BE-CAL-004: implement MinimumWorkload storage

- New model: minimum_workloads table with JSON config column (per-user)
- Schemas: MinimumWorkloadConfig, MinimumWorkloadUpdate, MinimumWorkloadResponse
- Service: CRUD operations + check_workload_warnings() entry point for BE-CAL-007
- API: GET/PUT/PATCH /calendar/workload-config (self + admin routes)
- Migration: auto-create minimum_workloads table on startup
- Registered calendar router in main.py
This commit is contained in:
zhi
2026-03-30 22:27:05 +00:00
parent 1c062ff4f1
commit eb57197020
5 changed files with 438 additions and 1 deletions

View File

@@ -62,6 +62,7 @@ from app.api.routers.proposes import router as proposes_router # legacy compat
from app.api.routers.milestone_actions import router as milestone_actions_router
from app.api.routers.meetings import router as meetings_router
from app.api.routers.essentials import router as essentials_router
from app.api.routers.calendar import router as calendar_router
app.include_router(auth_router)
app.include_router(tasks_router)
@@ -78,6 +79,7 @@ app.include_router(proposes_router) # legacy compat
app.include_router(milestone_actions_router)
app.include_router(meetings_router)
app.include_router(essentials_router)
app.include_router(calendar_router)
# Auto schema migration for lightweight deployments
@@ -303,6 +305,21 @@ def _migrate_schema():
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
"""))
# --- minimum_workloads table (BE-CAL-004) ---
if not _has_table(db, "minimum_workloads"):
db.execute(text("""
CREATE TABLE minimum_workloads (
id INTEGER NOT NULL AUTO_INCREMENT,
user_id INTEGER NOT NULL,
config JSON NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE INDEX idx_minimum_workloads_user_id (user_id),
CONSTRAINT fk_minimum_workloads_user_id FOREIGN KEY (user_id) REFERENCES users(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
"""))
db.commit()
except Exception as e:
db.rollback()
@@ -337,7 +354,7 @@ def _sync_default_user_roles(db):
@app.on_event("startup")
def startup():
from app.core.config import Base, engine, SessionLocal
from app.models import models, webhook, apikey, activity, milestone, notification, worklog, monitor, role_permission, task, support, meeting, proposal, propose, essential, agent, calendar
from app.models import models, webhook, apikey, activity, milestone, notification, worklog, monitor, role_permission, task, support, meeting, proposal, propose, essential, agent, calendar, minimum_workload
Base.metadata.create_all(bind=engine)
_migrate_schema()