Refactor backend to SQLModel; reset schema; add Company OS endpoints
This commit is contained in:
@@ -1,2 +1,17 @@
|
||||
# Import models here so Alembic can discover them
|
||||
from .task import Task # noqa: F401
|
||||
from app.models.org import Department, Employee
|
||||
from app.models.projects import Project, ProjectMember
|
||||
from app.models.work import Task, TaskComment
|
||||
from app.models.hr import HeadcountRequest, EmploymentAction
|
||||
from app.models.activity import Activity
|
||||
|
||||
__all__ = [
|
||||
"Department",
|
||||
"Employee",
|
||||
"Project",
|
||||
"ProjectMember",
|
||||
"Task",
|
||||
"TaskComment",
|
||||
"HeadcountRequest",
|
||||
"EmploymentAction",
|
||||
"Activity",
|
||||
]
|
||||
|
||||
Binary file not shown.
BIN
backend/app/models/__pycache__/activity.cpython-312.pyc
Normal file
BIN
backend/app/models/__pycache__/activity.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/hr.cpython-312.pyc
Normal file
BIN
backend/app/models/__pycache__/hr.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/org.cpython-312.pyc
Normal file
BIN
backend/app/models/__pycache__/org.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/projects.cpython-312.pyc
Normal file
BIN
backend/app/models/__pycache__/projects.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/app/models/__pycache__/work.cpython-312.pyc
Normal file
BIN
backend/app/models/__pycache__/work.cpython-312.pyc
Normal file
Binary file not shown.
19
backend/app/models/activity.py
Normal file
19
backend/app/models/activity.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class Activity(SQLModel, table=True):
|
||||
__tablename__ = "activities"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
actor_employee_id: int | None = Field(default=None, foreign_key="employees.id")
|
||||
|
||||
entity_type: str
|
||||
entity_id: int | None = None
|
||||
verb: str
|
||||
|
||||
payload_json: str | None = None
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
35
backend/app/models/hr.py
Normal file
35
backend/app/models/hr.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class HeadcountRequest(SQLModel, table=True):
|
||||
__tablename__ = "headcount_requests"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
department_id: int = Field(foreign_key="departments.id")
|
||||
requested_by_manager_id: int = Field(foreign_key="employees.id")
|
||||
|
||||
role_title: str
|
||||
employee_type: str # human | agent
|
||||
quantity: int = Field(default=1)
|
||||
|
||||
justification: str | None = None
|
||||
status: str = Field(default="submitted")
|
||||
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
|
||||
class EmploymentAction(SQLModel, table=True):
|
||||
__tablename__ = "employment_actions"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
employee_id: int = Field(foreign_key="employees.id")
|
||||
issued_by_employee_id: int = Field(foreign_key="employees.id")
|
||||
|
||||
action_type: str # praise|warning|pip|termination
|
||||
notes: str | None = None
|
||||
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
27
backend/app/models/org.py
Normal file
27
backend/app/models/org.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class Department(SQLModel, table=True):
|
||||
__tablename__ = "departments"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True, unique=True)
|
||||
head_employee_id: int | None = Field(default=None, foreign_key="employees.id")
|
||||
|
||||
|
||||
class Employee(SQLModel, table=True):
|
||||
__tablename__ = "employees"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
employee_type: str # human | agent
|
||||
|
||||
department_id: int | None = Field(default=None, foreign_key="departments.id")
|
||||
manager_id: int | None = Field(default=None, foreign_key="employees.id")
|
||||
|
||||
title: str | None = None
|
||||
status: str = Field(default="active")
|
||||
20
backend/app/models/projects.py
Normal file
20
backend/app/models/projects.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class Project(SQLModel, table=True):
|
||||
__tablename__ = "projects"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True, unique=True)
|
||||
status: str = Field(default="active")
|
||||
|
||||
|
||||
class ProjectMember(SQLModel, table=True):
|
||||
__tablename__ = "project_members"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
project_id: int = Field(foreign_key="projects.id")
|
||||
employee_id: int = Field(foreign_key="employees.id")
|
||||
role: str | None = None
|
||||
@@ -1,28 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, Integer, String, Text
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.db.base import Base
|
||||
|
||||
|
||||
class Task(Base):
|
||||
__tablename__ = "tasks"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
||||
title: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
# kanban columns: todo | doing | done
|
||||
status: Mapped[str] = mapped_column(String(32), nullable=False, default="todo")
|
||||
|
||||
# simple attribution (no auth)
|
||||
assignee: Mapped[str | None] = mapped_column(String(120), nullable=True)
|
||||
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
||||
)
|
||||
34
backend/app/models/work.py
Normal file
34
backend/app/models/work.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class Task(SQLModel, table=True):
|
||||
__tablename__ = "tasks"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
|
||||
project_id: int = Field(foreign_key="projects.id", index=True)
|
||||
title: str
|
||||
description: str | None = None
|
||||
|
||||
status: str = Field(default="backlog", index=True)
|
||||
|
||||
assignee_employee_id: int | None = Field(default=None, foreign_key="employees.id")
|
||||
reviewer_employee_id: int | None = Field(default=None, foreign_key="employees.id")
|
||||
created_by_employee_id: int | None = Field(default=None, foreign_key="employees.id")
|
||||
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
|
||||
class TaskComment(SQLModel, table=True):
|
||||
__tablename__ = "task_comments"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
task_id: int = Field(foreign_key="tasks.id", index=True)
|
||||
author_employee_id: int | None = Field(default=None, foreign_key="employees.id")
|
||||
body: str
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
Reference in New Issue
Block a user