Automated Action 27c9268a6a Implement HR platform backend with FastAPI and SQLite
- Set up project structure with FastAPI framework
- Create database models for users, employees, departments, and job titles
- Implement JWT authentication and authorization system
- Set up SQLite database with SQLAlchemy ORM
- Add Alembic migrations for database versioning
- Create CRUD API endpoints for employee management
- Implement category-based search functionality
- Add OpenAPI documentation and health check endpoint
- Update README with comprehensive setup and usage instructions
2025-06-03 01:18:41 +00:00

38 lines
1.6 KiB
Python

from sqlalchemy import Column, String, DateTime, Text, ForeignKey, Date, Boolean
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from uuid import uuid4
from app.db.base_class import Base
class Employee(Base):
id = Column(String, primary_key=True, index=True, default=lambda: str(uuid4()))
first_name = Column(String, index=True, nullable=False)
last_name = Column(String, index=True, nullable=False)
email = Column(String, unique=True, index=True, nullable=False)
phone = Column(String, nullable=True)
hire_date = Column(Date, nullable=False)
birth_date = Column(Date, nullable=True)
address = Column(Text, nullable=True)
# Foreign keys
department_id = Column(String, ForeignKey("department.id"), nullable=False)
job_title_id = Column(String, ForeignKey("jobtitle.id"), nullable=False)
manager_id = Column(String, ForeignKey("employee.id"), nullable=True)
# Relationships
department = relationship("Department", foreign_keys=[department_id])
job_title = relationship("JobTitle", foreign_keys=[job_title_id])
manager = relationship("Employee", remote_side=[id], backref="subordinates")
# Skills and categories for searching
skills = Column(Text, nullable=True) # Comma-separated list of skills
categories = Column(Text, nullable=True) # Comma-separated list of categories
# Status
is_active = Column(Boolean(), default=True)
# Audit fields
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())